diff --git a/websocket-sharp/Net/HttpConnection.cs b/websocket-sharp/Net/HttpConnection.cs index be565814..1d2480fc 100644 --- a/websocket-sharp/Net/HttpConnection.cs +++ b/websocket-sharp/Net/HttpConnection.cs @@ -533,13 +533,19 @@ namespace WebSocketSharp.Net res.StatusCode = status; res.ContentType = "text/html"; - var desc = status.GetStatusDescription (); var msg = message != null && message.Length > 0 - ? String.Format ("

{0} ({1})

", desc, message) - : String.Format ("

{0}

", desc); + ? String.Format ("{0} ({1})", res.StatusDescription, message) + : res.StatusDescription; - var entity = res.ContentEncoding.GetBytes (msg); - res.Close (entity, false); + var enc = res.ContentEncoding; + if (enc == null) { + enc = Encoding.UTF8; + res.ContentEncoding = enc; + } + + var entity = enc.GetBytes (String.Format ("

{0}

", msg)); + res.ContentLength64 = entity.LongLength; + res.Close (entity, true); } catch { // Response was already closed. diff --git a/websocket-sharp/Net/HttpListenerResponse.cs b/websocket-sharp/Net/HttpListenerResponse.cs index 3570ba22..94fc6346 100644 --- a/websocket-sharp/Net/HttpListenerResponse.cs +++ b/websocket-sharp/Net/HttpListenerResponse.cs @@ -743,20 +743,16 @@ namespace WebSocketSharp.Net /// /// is . /// - /// - /// The response has already been sent. - /// /// /// This object is closed. /// public void Close (byte[] responseEntity, bool willBlock) { + checkDisposed (); if (responseEntity == null) throw new ArgumentNullException ("responseEntity"); var len = responseEntity.Length; - ContentLength64 = len; - var output = OutputStream; if (willBlock) { output.Write (responseEntity, 0, len);