Refactored a few for HttpConnection.cs

This commit is contained in:
sta 2015-06-11 15:43:09 +09:00
parent a588d8e648
commit 97b4ca3cf8

View File

@ -61,7 +61,7 @@ namespace WebSocketSharp.Net
private byte[] _buffer; private byte[] _buffer;
private const int _bufferLength = 8192; private const int _bufferLength = 8192;
private HttpListenerContext _context; private HttpListenerContext _context;
private bool _contextWasBound; private bool _contextBound;
private StringBuilder _currentLine; private StringBuilder _currentLine;
private InputState _inputState; private InputState _inputState;
private RequestStream _inputStream; private RequestStream _inputStream;
@ -299,7 +299,7 @@ namespace WebSocketSharp.Net
conn._lastListener = lsnr; conn._lastListener = lsnr;
} }
conn._contextWasBound = true; conn._contextBound = true;
lsnr.RegisterContext (conn._context); lsnr.RegisterContext (conn._context);
return; return;
@ -399,11 +399,11 @@ namespace WebSocketSharp.Net
private void unbind () private void unbind ()
{ {
if (!_contextWasBound) if (!_contextBound)
return; return;
_listener.UnbindContext (_context); _listener.UnbindContext (_context);
_contextWasBound = false; _contextBound = false;
} }
#endregion #endregion
@ -530,9 +530,12 @@ namespace WebSocketSharp.Net
res.StatusCode = status; res.StatusCode = status;
res.ContentType = "text/html"; res.ContentType = "text/html";
var msg = message != null && message.Length > 0 var content = new StringBuilder (64);
? String.Format ("{0} ({1})", res.StatusDescription, message) content.AppendFormat ("<html><body><h1>{0} {1}", status, res.StatusDescription);
: res.StatusDescription; if (message != null && message.Length > 0)
content.AppendFormat (" ({0})</h1></body></html>", message);
else
content.Append ("</h1></body></html>");
var enc = res.ContentEncoding; var enc = res.ContentEncoding;
if (enc == null) { if (enc == null) {
@ -540,7 +543,7 @@ namespace WebSocketSharp.Net
res.ContentEncoding = enc; res.ContentEncoding = enc;
} }
var entity = enc.GetBytes (String.Format ("<html><body><h1>{0}</h1></body></html>", msg)); var entity = enc.GetBytes (content.ToString ());
res.ContentLength64 = entity.LongLength; res.ContentLength64 = entity.LongLength;
res.Close (entity, true); res.Close (entity, true);
} }