|
|
|
@ -125,16 +125,11 @@ namespace WebSocketSharp.Net
|
|
|
|
|
|
|
|
|
|
|
|
#region Private Methods
|
|
|
|
#region Private Methods
|
|
|
|
|
|
|
|
|
|
|
|
private void flush (bool closing)
|
|
|
|
private bool flush (bool closing)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!_response.HeadersSent) {
|
|
|
|
if (!_response.HeadersSent) {
|
|
|
|
using (var headers = new MemoryStream ()) {
|
|
|
|
if (!flushHeaders (closing))
|
|
|
|
_response.WriteHeadersTo (headers, closing);
|
|
|
|
return false;
|
|
|
|
var start = headers.Position;
|
|
|
|
|
|
|
|
_write (headers.GetBuffer (), (int) start, (int) (headers.Length - start));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_response.HeadersSent = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_chunked = _response.SendChunked;
|
|
|
|
_chunked = _response.SendChunked;
|
|
|
|
_writeBody = _chunked ? _writeChunked : _write;
|
|
|
|
_writeBody = _chunked ? _writeChunked : _write;
|
|
|
|
@ -145,6 +140,8 @@ namespace WebSocketSharp.Net
|
|
|
|
var last = getChunkSizeBytes (0, true);
|
|
|
|
var last = getChunkSizeBytes (0, true);
|
|
|
|
_write (last, 0, last.Length);
|
|
|
|
_write (last, 0, last.Length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void flushBody (bool closing)
|
|
|
|
private void flushBody (bool closing)
|
|
|
|
@ -167,6 +164,25 @@ namespace WebSocketSharp.Net
|
|
|
|
_body = !closing ? new MemoryStream () : null;
|
|
|
|
_body = !closing ? new MemoryStream () : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool flushHeaders (bool closing)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var headers = new MemoryStream ()) {
|
|
|
|
|
|
|
|
_response.WriteHeadersTo (headers, closing);
|
|
|
|
|
|
|
|
var start = headers.Position;
|
|
|
|
|
|
|
|
var len = headers.Length - start;
|
|
|
|
|
|
|
|
if (len > 32768)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!_response.SendChunked && _response.ContentLength64 != _body.Length)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_write (headers.GetBuffer (), (int) start, (int) len);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_response.HeadersSent = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static byte[] getChunkSizeBytes (int size, bool final)
|
|
|
|
private static byte[] getChunkSizeBytes (int size, bool final)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Encoding.ASCII.GetBytes (String.Format ("{0:x}\r\n{1}", size, final ? "\r\n" : ""));
|
|
|
|
return Encoding.ASCII.GetBytes (String.Format ("{0:x}\r\n{1}", size, final ? "\r\n" : ""));
|
|
|
|
@ -208,18 +224,18 @@ namespace WebSocketSharp.Net
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
_disposed = true;
|
|
|
|
_disposed = true;
|
|
|
|
if (!force) {
|
|
|
|
if (!force && flush (true)) {
|
|
|
|
flush (true);
|
|
|
|
|
|
|
|
_response.Close ();
|
|
|
|
_response.Close ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
_body.Dispose ();
|
|
|
|
|
|
|
|
_body = null;
|
|
|
|
|
|
|
|
if (_chunked) {
|
|
|
|
if (_chunked) {
|
|
|
|
var last = getChunkSizeBytes (0, true);
|
|
|
|
var last = getChunkSizeBytes (0, true);
|
|
|
|
_write (last, 0, last.Length);
|
|
|
|
_write (last, 0, last.Length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_body.Dispose ();
|
|
|
|
|
|
|
|
_body = null;
|
|
|
|
|
|
|
|
|
|
|
|
_response.Abort ();
|
|
|
|
_response.Abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|