Refactored a few for HttpListenerResponse.cs
This commit is contained in:
parent
9ad62f6a5f
commit
8645185321
@ -55,11 +55,9 @@ namespace WebSocketSharp.Net
|
|||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
|
|
||||||
private bool _chunked;
|
|
||||||
private bool _closeConnection;
|
private bool _closeConnection;
|
||||||
private Encoding _contentEncoding;
|
private Encoding _contentEncoding;
|
||||||
private long _contentLength;
|
private long _contentLength;
|
||||||
private bool _contentLengthSet;
|
|
||||||
private string _contentType;
|
private string _contentType;
|
||||||
private HttpListenerContext _context;
|
private HttpListenerContext _context;
|
||||||
private CookieCollection _cookies;
|
private CookieCollection _cookies;
|
||||||
@ -69,6 +67,7 @@ namespace WebSocketSharp.Net
|
|||||||
private bool _keepAlive;
|
private bool _keepAlive;
|
||||||
private string _location;
|
private string _location;
|
||||||
private ResponseStream _outputStream;
|
private ResponseStream _outputStream;
|
||||||
|
private bool _sendChunked;
|
||||||
private int _statusCode;
|
private int _statusCode;
|
||||||
private string _statusDescription;
|
private string _statusDescription;
|
||||||
private Version _version;
|
private Version _version;
|
||||||
@ -160,7 +159,6 @@ namespace WebSocketSharp.Net
|
|||||||
if (value < 0)
|
if (value < 0)
|
||||||
throw new ArgumentOutOfRangeException ("Less than zero.", "value");
|
throw new ArgumentOutOfRangeException ("Less than zero.", "value");
|
||||||
|
|
||||||
_contentLengthSet = true;
|
|
||||||
_contentLength = value;
|
_contentLength = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,7 +343,8 @@ namespace WebSocketSharp.Net
|
|||||||
/// Gets or sets a value indicating whether the response uses the chunked transfer encoding.
|
/// Gets or sets a value indicating whether the response uses the chunked transfer encoding.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// <c>true</c> if the response uses the chunked transfer encoding; otherwise, <c>false</c>.
|
/// <c>true</c> if the response uses the chunked transfer encoding;
|
||||||
|
/// otherwise, <c>false</c>. The default value is <c>false</c>.
|
||||||
/// </value>
|
/// </value>
|
||||||
/// <exception cref="InvalidOperationException">
|
/// <exception cref="InvalidOperationException">
|
||||||
/// The response has already been sent.
|
/// The response has already been sent.
|
||||||
@ -355,12 +354,12 @@ namespace WebSocketSharp.Net
|
|||||||
/// </exception>
|
/// </exception>
|
||||||
public bool SendChunked {
|
public bool SendChunked {
|
||||||
get {
|
get {
|
||||||
return _chunked;
|
return _sendChunked;
|
||||||
}
|
}
|
||||||
|
|
||||||
set {
|
set {
|
||||||
checkDisposedOrHeadersSent ();
|
checkDisposedOrHeadersSent ();
|
||||||
_chunked = value;
|
_sendChunked = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,7 +492,7 @@ namespace WebSocketSharp.Net
|
|||||||
|
|
||||||
#region Internal Methods
|
#region Internal Methods
|
||||||
|
|
||||||
internal WebHeaderCollection WriteHeadersTo (MemoryStream destination, bool closing)
|
internal WebHeaderCollection WriteHeadersTo (MemoryStream destination)
|
||||||
{
|
{
|
||||||
var headers = new WebHeaderCollection (HttpHeaderType.Response, true);
|
var headers = new WebHeaderCollection (HttpHeaderType.Response, true);
|
||||||
if (_headers != null)
|
if (_headers != null)
|
||||||
@ -515,19 +514,9 @@ namespace WebSocketSharp.Net
|
|||||||
if (headers["Date"] == null)
|
if (headers["Date"] == null)
|
||||||
headers.InternalSet ("Date", DateTime.UtcNow.ToString ("r", prov), true);
|
headers.InternalSet ("Date", DateTime.UtcNow.ToString ("r", prov), true);
|
||||||
|
|
||||||
if (!_chunked) {
|
if (!_sendChunked)
|
||||||
if (!_contentLengthSet && closing) {
|
headers.InternalSet ("Content-Length", _contentLength.ToString (prov), true);
|
||||||
_contentLengthSet = true;
|
else
|
||||||
_contentLength = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_contentLengthSet)
|
|
||||||
headers.InternalSet ("Content-Length", _contentLength.ToString (prov), true);
|
|
||||||
else if (_context.Request.ProtocolVersion > HttpVersion.Version10)
|
|
||||||
_chunked = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_chunked)
|
|
||||||
headers.InternalSet ("Transfer-Encoding", "chunked", true);
|
headers.InternalSet ("Transfer-Encoding", "chunked", true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -761,7 +750,6 @@ namespace WebSocketSharp.Net
|
|||||||
}
|
}
|
||||||
|
|
||||||
_contentLength = templateResponse._contentLength;
|
_contentLength = templateResponse._contentLength;
|
||||||
_contentLengthSet = templateResponse._contentLengthSet;
|
|
||||||
_statusCode = templateResponse._statusCode;
|
_statusCode = templateResponse._statusCode;
|
||||||
_statusDescription = templateResponse._statusDescription;
|
_statusDescription = templateResponse._statusDescription;
|
||||||
_keepAlive = templateResponse._keepAlive;
|
_keepAlive = templateResponse._keepAlive;
|
||||||
|
@ -171,7 +171,7 @@ namespace WebSocketSharp.Net
|
|||||||
private bool flushHeaders (bool closing)
|
private bool flushHeaders (bool closing)
|
||||||
{
|
{
|
||||||
using (var buff = new MemoryStream ()) {
|
using (var buff = new MemoryStream ()) {
|
||||||
var headers = _response.WriteHeadersTo (buff, closing);
|
var headers = _response.WriteHeadersTo (buff);
|
||||||
var start = buff.Position;
|
var start = buff.Position;
|
||||||
var len = buff.Length - start;
|
var len = buff.Length - start;
|
||||||
if (len > 32768)
|
if (len > 32768)
|
||||||
|
Loading…
Reference in New Issue
Block a user