diff --git a/HTTPServer.cs b/HTTPServer.cs index 7e73a80..d144d5f 100644 --- a/HTTPServer.cs +++ b/HTTPServer.cs @@ -81,18 +81,18 @@ namespace ln.http lock (this) { this.shutdown = true; + } - foreach (TcpListener tcpListener in tcpListeners.Values) - { - tcpListener.Stop(); - } + foreach (TcpListener tcpListener in tcpListeners.Values) + { + tcpListener.Stop(); + } - threadPool.NumThreads = 0; + threadPool.NumThreads = 0; - while (IsRunning) - { - Thread.Sleep(50); - } + while (IsRunning) + { + Thread.Sleep(50); } } diff --git a/HttpRequest.cs b/HttpRequest.cs index 316245f..8e52fac 100644 --- a/HttpRequest.cs +++ b/HttpRequest.cs @@ -32,6 +32,21 @@ namespace ln.http public Session Session { get; private set; } + public MemoryStream ContentStream { get; } + public TextReader ContentReader + { + get + { + if (contentReader == null) + contentReader = new StreamReader(ContentStream); + return contentReader; + } + } + + + StreamReader contentReader; + byte[] requestBody; + public HttpRequest(HttpReader httpReader,IPEndPoint localEndpoint) { LocalEndpoint = localEndpoint; @@ -44,6 +59,19 @@ namespace ln.http requestCookies = new Dictionary(); Setup(); + + + int clength = int.Parse(GetRequestHeader("content-length", "0")); + requestBody = new byte[clength]; + + if (clength > 0) + { + int nread = httpReader.ReadRequestBody(requestBody, 0, clength); + if (nread != clength) + throw new HttpException(500,"failed to read request content"); + } + + ContentStream = new MemoryStream(requestBody); } private void Setup() @@ -140,7 +168,10 @@ namespace ln.http return requestCookies[name]; } - + public string self() + { + return BaseURI.ToString(); + }