Refactored HttpListenerRequest.cs
This commit is contained in:
parent
c1dd8d659e
commit
034e245272
@ -55,15 +55,9 @@ namespace WebSocketSharp.Net
|
||||
/// </remarks>
|
||||
public sealed class HttpListenerRequest
|
||||
{
|
||||
#region Private Static Fields
|
||||
|
||||
private static byte [] _100continue =
|
||||
Encoding.ASCII.GetBytes ("HTTP/1.1 100 Continue\r\n\r\n");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static readonly byte[] _100continue;
|
||||
private string[] _acceptTypes;
|
||||
private bool _chunked;
|
||||
private Encoding _contentEncoding;
|
||||
@ -88,6 +82,15 @@ namespace WebSocketSharp.Net
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Constructor
|
||||
|
||||
static HttpListenerRequest ()
|
||||
{
|
||||
_100continue = Encoding.ASCII.GetBytes ("HTTP/1.1 100 Continue\r\n\r\n");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Constructors
|
||||
|
||||
internal HttpListenerRequest (HttpListenerContext context)
|
||||
@ -464,12 +467,12 @@ namespace WebSocketSharp.Net
|
||||
|
||||
private static bool tryCreateVersion (string version, out Version result)
|
||||
{
|
||||
result = null;
|
||||
try {
|
||||
result = new Version (version);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -502,9 +505,9 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
|
||||
if (lower == "content-length") {
|
||||
long length;
|
||||
if (Int64.TryParse (val, out length) && length >= 0) {
|
||||
_contentLength = length;
|
||||
long len;
|
||||
if (Int64.TryParse (val, out len) && len >= 0) {
|
||||
_contentLength = len;
|
||||
_contentLengthWasSet = true;
|
||||
}
|
||||
else {
|
||||
@ -515,11 +518,11 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
|
||||
if (lower == "content-type") {
|
||||
var contents = val.Split (';');
|
||||
foreach (var content in contents) {
|
||||
var tmp = content.Trim ();
|
||||
if (tmp.StartsWith ("charset")) {
|
||||
var charset = tmp.GetValue ("=");
|
||||
var parts = val.Split (';');
|
||||
foreach (var p in parts) {
|
||||
var part = p.Trim ();
|
||||
if (part.StartsWith ("charset", StringComparison.OrdinalIgnoreCase)) {
|
||||
var charset = part.GetValue ("=");
|
||||
if (charset != null && charset.Length > 0) {
|
||||
try {
|
||||
_contentEncoding = Encoding.GetEncoding (charset.Trim ('"'));
|
||||
@ -592,15 +595,15 @@ namespace WebSocketSharp.Net
|
||||
if (!HasEntityBody)
|
||||
return true;
|
||||
|
||||
var length = 2048;
|
||||
var len = 2048;
|
||||
if (_contentLength > 0)
|
||||
length = (int) Math.Min (_contentLength, (long) length);
|
||||
len = (int) Math.Min (_contentLength, (long) len);
|
||||
|
||||
var buff = new byte [length];
|
||||
var buff = new byte[len];
|
||||
while (true) {
|
||||
// TODO: Test if MS has a timeout when doing this.
|
||||
try {
|
||||
var ares = InputStream.BeginRead (buff, 0, length, null, null);
|
||||
var ares = InputStream.BeginRead (buff, 0, len, null, null);
|
||||
if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne (100))
|
||||
return false;
|
||||
|
||||
@ -715,11 +718,11 @@ namespace WebSocketSharp.Net
|
||||
/// </returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
var buff = new StringBuilder (64);
|
||||
buff.AppendFormat ("{0} {1} HTTP/{2}\r\n", _method, _uri, _version);
|
||||
buff.Append (_headers.ToString ());
|
||||
var output = new StringBuilder (64);
|
||||
output.AppendFormat ("{0} {1} HTTP/{2}\r\n", _method, _uri, _version);
|
||||
output.Append (_headers.ToString ());
|
||||
|
||||
return buff.ToString ();
|
||||
return output.ToString ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Loading…
Reference in New Issue
Block a user