Fix a few for HandshakeRequest.cs

This commit is contained in:
sta 2014-07-09 10:59:32 +09:00
parent f8ffb763c0
commit 9f0f54f4cd

View File

@ -53,15 +53,15 @@ namespace WebSocketSharp
#region Public Constructors #region Public Constructors
public HandshakeRequest (string absPathAndQuery) public HandshakeRequest (string pathAndQuery)
{ {
_uri = absPathAndQuery; _uri = pathAndQuery;
_method = "GET"; _method = "GET";
var headers = Headers; var headers = Headers;
headers ["User-Agent"] = "websocket-sharp/1.0"; headers["User-Agent"] = "websocket-sharp/1.0";
headers ["Upgrade"] = "websocket"; headers["Upgrade"] = "websocket";
headers ["Connection"] = "Upgrade"; headers["Connection"] = "Upgrade";
} }
#endregion #endregion
@ -70,7 +70,7 @@ namespace WebSocketSharp
public AuthenticationResponse AuthResponse { public AuthenticationResponse AuthResponse {
get { get {
var auth = Headers ["Authorization"]; var auth = Headers["Authorization"];
return auth != null && auth.Length > 0 return auth != null && auth.Length > 0
? AuthenticationResponse.Parse (auth) ? AuthenticationResponse.Parse (auth)
: null; : null;
@ -123,21 +123,21 @@ namespace WebSocketSharp
#region Public Methods #region Public Methods
public static HandshakeRequest Parse (string [] headerParts) public static HandshakeRequest Parse (string[] headerParts)
{ {
var requestLine = headerParts [0].Split (new [] { ' ' }, 3); var requestLine = headerParts[0].Split (new[] { ' ' }, 3);
if (requestLine.Length != 3) if (requestLine.Length != 3)
throw new ArgumentException ("Invalid request line: " + headerParts [0]); throw new ArgumentException ("Invalid request line: " + headerParts[0]);
var headers = new WebHeaderCollection (); var headers = new WebHeaderCollection ();
for (int i = 1; i < headerParts.Length; i++) for (int i = 1; i < headerParts.Length; i++)
headers.SetInternally (headerParts [i], false); headers.SetInternally (headerParts[i], false);
return new HandshakeRequest { return new HandshakeRequest {
Headers = headers, Headers = headers,
HttpMethod = requestLine [0], HttpMethod = requestLine[0],
ProtocolVersion = new Version (requestLine [2].Substring (5)), ProtocolVersion = new Version (requestLine[2].Substring (5)),
RequestUri = requestLine [1] RequestUri = requestLine[1]
}; };
} }
@ -154,7 +154,7 @@ namespace WebSocketSharp
var len = buff.Length; var len = buff.Length;
if (len > 2) { if (len > 2) {
buff.Length = len - 2; buff.Length = len - 2;
Headers ["Cookie"] = buff.ToString (); Headers["Cookie"] = buff.ToString ();
} }
} }
@ -165,7 +165,7 @@ namespace WebSocketSharp
var headers = Headers; var headers = Headers;
foreach (var key in headers.AllKeys) foreach (var key in headers.AllKeys)
output.AppendFormat ("{0}: {1}{2}", key, headers [key], CrLf); output.AppendFormat ("{0}: {1}{2}", key, headers[key], CrLf);
output.Append (CrLf); output.Append (CrLf);