[Modify] Polish it
This commit is contained in:
parent
4cbd1e0ccd
commit
b75699010a
@ -631,20 +631,26 @@ namespace WebSocketSharp.Net
|
|||||||
internal void AddHeader (string headerField)
|
internal void AddHeader (string headerField)
|
||||||
{
|
{
|
||||||
var start = headerField[0];
|
var start = headerField[0];
|
||||||
|
|
||||||
if (start == ' ' || start == '\t') {
|
if (start == ' ' || start == '\t') {
|
||||||
_context.ErrorMessage = "Invalid header field";
|
_context.ErrorMessage = "Invalid header field";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var colon = headerField.IndexOf (':');
|
var colon = headerField.IndexOf (':');
|
||||||
|
|
||||||
if (colon < 1) {
|
if (colon < 1) {
|
||||||
_context.ErrorMessage = "Invalid header field";
|
_context.ErrorMessage = "Invalid header field";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = headerField.Substring (0, colon).Trim ();
|
var name = headerField.Substring (0, colon).Trim ();
|
||||||
|
|
||||||
if (name.Length == 0 || !name.IsToken ()) {
|
if (name.Length == 0 || !name.IsToken ()) {
|
||||||
_context.ErrorMessage = "Invalid header name";
|
_context.ErrorMessage = "Invalid header name";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,39 +661,48 @@ namespace WebSocketSharp.Net
|
|||||||
_headers.InternalSet (name, val, false);
|
_headers.InternalSet (name, val, false);
|
||||||
|
|
||||||
var lower = name.ToLower (CultureInfo.InvariantCulture);
|
var lower = name.ToLower (CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
if (lower == "host") {
|
if (lower == "host") {
|
||||||
if (_userHostName != null) {
|
if (_userHostName != null) {
|
||||||
_context.ErrorMessage = "Invalid Host header";
|
_context.ErrorMessage = "Invalid Host header";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val.Length == 0) {
|
if (val.Length == 0) {
|
||||||
_context.ErrorMessage = "Invalid Host header";
|
_context.ErrorMessage = "Invalid Host header";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_userHostName = val;
|
_userHostName = val;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lower == "content-length") {
|
if (lower == "content-length") {
|
||||||
if (_contentLength > -1) {
|
if (_contentLength > -1) {
|
||||||
_context.ErrorMessage = "Invalid Content-Length header";
|
_context.ErrorMessage = "Invalid Content-Length header";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long len;
|
long len;
|
||||||
|
|
||||||
if (!Int64.TryParse (val, out len)) {
|
if (!Int64.TryParse (val, out len)) {
|
||||||
_context.ErrorMessage = "Invalid Content-Length header";
|
_context.ErrorMessage = "Invalid Content-Length header";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
_context.ErrorMessage = "Invalid Content-Length header";
|
_context.ErrorMessage = "Invalid Content-Length header";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_contentLength = len;
|
_contentLength = len;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user