private void HandlePOSTRequest(IStreamWrapper inputStream, IStreamWriterWrapper outputStream) { // this post data processing just reads everything into a memory stream. // this is fine for smallish things, but for large stuff we should really // hand an input stream to the request processor. However, the input stream // we hand him needs to let him see the "end of the stream" at this content // length, because otherwise he won't know when he's seen it all! //Console.WriteLine("get post data start"); using (var ms = streamFactory.GetMemoryStreamWrapper()) { if (httpHeaders.ContainsKey("Content-Length")) { var contentLen = Convert.ToInt32(httpHeaders["Content-Length"]); if (contentLen > MaxPostSize) { throw new Exception($"POST Content-Length({contentLen}) too big for this server"); } var buf = new byte[BufSize]; var toRead = contentLen; while (toRead > 0) { //Console.WriteLine("starting Read, to_read={0}", toRead); var numread = inputStream.Read(buf, 0, Math.Min(BufSize, toRead)); //Console.WriteLine("read finished, numread={0}", numread); if (numread == 0) { if (toRead == 0) { break; } throw new Exception("client disconnected during post"); } toRead -= numread; ms.Write(buf, 0, numread); } ms.Seek(0, SeekOrigin.Begin); } //Console.WriteLine("get post data end"); postHandler(httpUrl, ms, outputStream); } }