diff --git a/VAR.HttpServer/HttpProcessor.cs b/VAR.HttpServer/HttpProcessor.cs index ecedbde..d92b400 100644 --- a/VAR.HttpServer/HttpProcessor.cs +++ b/VAR.HttpServer/HttpProcessor.cs @@ -85,6 +85,7 @@ namespace VAR.HttpServer catch (Exception) { ResponseServerError(); + throw; } _outputStream.Flush(); _inputStream = null; @@ -149,7 +150,7 @@ namespace VAR.HttpServer int separator = line.IndexOf(':'); if (separator == -1) { - throw new Exception("invalid http header line: " + line); + throw new Exception(string.Format("Invalid HTTP header line: {0}", line)); } string name = line.Substring(0, separator); int pos = separator + 1; @@ -167,22 +168,20 @@ namespace VAR.HttpServer private void ReadPostData() { - int content_len = 0; + int contentLen = 0; MemoryStream ms = new MemoryStream(); - if (this._httpHeaders.ContainsKey("Content-Length")) + if (_httpHeaders.ContainsKey("Content-Length")) { - content_len = Convert.ToInt32(this._httpHeaders["Content-Length"]); - if (content_len > MaxPostSize) + contentLen = Convert.ToInt32(_httpHeaders["Content-Length"]); + if (contentLen > MaxPostSize) { - throw new Exception( - string.Format("POST Content-Length({0}) too big for this simple server", - content_len)); + throw new Exception(string.Format("POST Content-Length({0}) > MaxPostSize({1})", contentLen, MaxPostSize)); } byte[] buf = new byte[BufferSize]; - int to_read = content_len; + int to_read = contentLen; while (to_read > 0) { - int numread = this._inputStream.Read(buf, 0, Math.Min(BufferSize, to_read)); + int numread = _inputStream.Read(buf, 0, Math.Min(BufferSize, to_read)); if (numread == 0) { if (to_read == 0) @@ -191,7 +190,7 @@ namespace VAR.HttpServer } else { - throw new Exception("client disconnected during post"); + throw new Exception("Client disconnected during POST"); } } to_read -= numread; @@ -237,7 +236,6 @@ namespace VAR.HttpServer _outputStream.WriteLine(string.Format("Content-Type: {0}", contentType)); _outputStream.WriteLine("Connection: close"); _outputStream.WriteLine(""); - _outputStream.Flush(); } catch (Exception ex) { @@ -252,7 +250,6 @@ namespace VAR.HttpServer _outputStream.WriteLine("HTTP/1.0 500 Internal server error"); _outputStream.WriteLine("Connection: close"); _outputStream.WriteLine(""); - _outputStream.Flush(); } catch (Exception ex) {