Fix due to the modified WebHeaderCollection.cs
This commit is contained in:
99
websocket-sharp/Net/HttpHeaderInfo.cs
Normal file
99
websocket-sharp/Net/HttpHeaderInfo.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// HttpHeaderInfo.cs
|
||||
//
|
||||
// Authors:
|
||||
// sta (sta.blockhead@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2013 sta.blockhead (sta.blockhead@gmail.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace WebSocketSharp.Net {
|
||||
|
||||
class HttpHeaderInfo {
|
||||
|
||||
#region Constructor
|
||||
|
||||
public HttpHeaderInfo ()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public bool IsMultiValueInRequest {
|
||||
get {
|
||||
return (Type & HttpHeaderType.MultiValueInRequest) == HttpHeaderType.MultiValueInRequest;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsMultiValueInResponse {
|
||||
get {
|
||||
return (Type & HttpHeaderType.MultiValueInResponse) == HttpHeaderType.MultiValueInResponse;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRequest {
|
||||
get {
|
||||
return (Type & HttpHeaderType.Request) == HttpHeaderType.Request;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsResponse {
|
||||
get {
|
||||
return (Type & HttpHeaderType.Response) == HttpHeaderType.Response;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public HttpHeaderType Type { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public bool IsMultiValue (bool response)
|
||||
{
|
||||
return (Type & HttpHeaderType.MultiValue) != HttpHeaderType.MultiValue
|
||||
? response
|
||||
? IsMultiValueInResponse
|
||||
: IsMultiValueInRequest
|
||||
: response
|
||||
? IsResponse
|
||||
: IsRequest;
|
||||
}
|
||||
|
||||
public bool IsRestricted (bool response)
|
||||
{
|
||||
return (Type & HttpHeaderType.Restricted) != HttpHeaderType.Restricted
|
||||
? false
|
||||
: response
|
||||
? IsResponse
|
||||
: IsRequest;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
44
websocket-sharp/Net/HttpHeaderType.cs
Normal file
44
websocket-sharp/Net/HttpHeaderType.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// HttpHeaderType.cs
|
||||
//
|
||||
// Authors:
|
||||
// sta (sta.blockhead@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2013 sta.blockhead (sta.blockhead@gmail.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace WebSocketSharp.Net {
|
||||
|
||||
[Flags]
|
||||
enum HttpHeaderType
|
||||
{
|
||||
Undefined,
|
||||
Request,
|
||||
Response,
|
||||
Restricted,
|
||||
MultiValue,
|
||||
MultiValueInRequest,
|
||||
MultiValueInResponse
|
||||
}
|
||||
}
|
@@ -112,7 +112,7 @@ namespace WebSocketSharp.Net {
|
||||
public int ClientCertificateError {
|
||||
// TODO: Always returns 0
|
||||
get {
|
||||
/*
|
||||
/*
|
||||
if (no_get_certificate)
|
||||
throw new InvalidOperationException (
|
||||
"Call GetClientCertificate() before calling this method.");
|
||||
@@ -470,7 +470,7 @@ namespace WebSocketSharp.Net {
|
||||
string name = header.Substring (0, colon).Trim ();
|
||||
string val = header.Substring (colon + 1).Trim ();
|
||||
string lower = name.ToLower (CultureInfo.InvariantCulture);
|
||||
headers.SetInternal (name, val);
|
||||
headers.SetInternal (name, val, false);
|
||||
switch (lower) {
|
||||
case "accept-language":
|
||||
user_languages = val.Split (','); // yes, only split with a ','
|
||||
|
@@ -483,18 +483,18 @@ namespace WebSocketSharp.Net {
|
||||
if (content_type != null) {
|
||||
if (content_encoding != null && content_type.IndexOf ("charset=", StringComparison.Ordinal) == -1) {
|
||||
string enc_name = content_encoding.WebName;
|
||||
headers.SetInternal ("Content-Type", content_type + "; charset=" + enc_name);
|
||||
headers.SetInternal ("Content-Type", content_type + "; charset=" + enc_name, true);
|
||||
} else {
|
||||
headers.SetInternal ("Content-Type", content_type);
|
||||
headers.SetInternal ("Content-Type", content_type, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (headers ["Server"] == null)
|
||||
headers.SetInternal ("Server", "WebSocketSharp-HTTPAPI/1.0");
|
||||
headers.SetInternal ("Server", "WebSocketSharp-HTTPAPI/1.0", true);
|
||||
|
||||
CultureInfo inv = CultureInfo.InvariantCulture;
|
||||
if (headers ["Date"] == null)
|
||||
headers.SetInternal ("Date", DateTime.UtcNow.ToString ("r", inv));
|
||||
headers.SetInternal ("Date", DateTime.UtcNow.ToString ("r", inv), true);
|
||||
|
||||
if (!chunked) {
|
||||
if (!cl_set && closing) {
|
||||
@@ -503,7 +503,7 @@ namespace WebSocketSharp.Net {
|
||||
}
|
||||
|
||||
if (cl_set)
|
||||
headers.SetInternal ("Content-Length", content_length.ToString (inv));
|
||||
headers.SetInternal ("Content-Length", content_length.ToString (inv), true);
|
||||
}
|
||||
|
||||
Version v = context.Request.ProtocolVersion;
|
||||
@@ -528,39 +528,39 @@ namespace WebSocketSharp.Net {
|
||||
|
||||
// They sent both KeepAlive: true and Connection: close!?
|
||||
if (!keep_alive || conn_close) {
|
||||
headers.SetInternal ("Connection", "close");
|
||||
headers.SetInternal ("Connection", "close", true);
|
||||
conn_close = true;
|
||||
}
|
||||
|
||||
if (chunked)
|
||||
headers.SetInternal ("Transfer-Encoding", "chunked");
|
||||
headers.SetInternal ("Transfer-Encoding", "chunked", true);
|
||||
|
||||
int reuses = context.Connection.Reuses;
|
||||
if (reuses >= 100) {
|
||||
force_close_chunked = true;
|
||||
if (!conn_close) {
|
||||
headers.SetInternal ("Connection", "close");
|
||||
headers.SetInternal ("Connection", "close", true);
|
||||
conn_close = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!conn_close) {
|
||||
headers.SetInternal ("Keep-Alive", String.Format ("timeout=15,max={0}", 100 - reuses));
|
||||
headers.SetInternal ("Keep-Alive", String.Format ("timeout=15,max={0}", 100 - reuses), true);
|
||||
if (context.Request.ProtocolVersion <= HttpVersion.Version10)
|
||||
headers.SetInternal ("Connection", "keep-alive");
|
||||
headers.SetInternal ("Connection", "keep-alive", true);
|
||||
}
|
||||
|
||||
if (location != null)
|
||||
headers.SetInternal ("Location", location);
|
||||
headers.SetInternal ("Location", location, true);
|
||||
|
||||
if (cookies != null) {
|
||||
foreach (Cookie cookie in cookies)
|
||||
headers.SetInternal ("Set-Cookie", cookie.ToClientString ());
|
||||
headers.SetInternal ("Set-Cookie", cookie.ToClientString (), true);
|
||||
}
|
||||
|
||||
StreamWriter writer = new StreamWriter (ms, encoding, 256);
|
||||
writer.Write ("HTTP/{0} {1} {2}\r\n", version, status_code, status_description);
|
||||
string headers_str = headers.ToStringMultiValue ();
|
||||
string headers_str = headers.ToStringMultiValue (true);
|
||||
writer.Write (headers_str);
|
||||
writer.Flush ();
|
||||
int preamble = (encoding.CodePage == 65001) ? 3 : encoding.GetPreamble ().Length;
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user