[Modify] Polish it
This commit is contained in:
parent
45db0ea477
commit
34cb643273
@ -784,47 +784,60 @@ namespace WebSocketSharp.Net
|
|||||||
internal void SetRequestLine (string requestLine)
|
internal void SetRequestLine (string requestLine)
|
||||||
{
|
{
|
||||||
var parts = requestLine.Split (new[] { ' ' }, 3);
|
var parts = requestLine.Split (new[] { ' ' }, 3);
|
||||||
|
|
||||||
if (parts.Length < 3) {
|
if (parts.Length < 3) {
|
||||||
_context.ErrorMessage = "Invalid request line (parts)";
|
_context.ErrorMessage = "Invalid request line (parts)";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var method = parts[0];
|
var method = parts[0];
|
||||||
|
|
||||||
if (method.Length == 0) {
|
if (method.Length == 0) {
|
||||||
_context.ErrorMessage = "Invalid request line (method)";
|
_context.ErrorMessage = "Invalid request line (method)";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var target = parts[1];
|
var target = parts[1];
|
||||||
|
|
||||||
if (target.Length == 0) {
|
if (target.Length == 0) {
|
||||||
_context.ErrorMessage = "Invalid request line (target)";
|
_context.ErrorMessage = "Invalid request line (target)";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rawVer = parts[2];
|
var rawVer = parts[2];
|
||||||
|
|
||||||
if (rawVer.Length != 8) {
|
if (rawVer.Length != 8) {
|
||||||
_context.ErrorMessage = "Invalid request line (version)";
|
_context.ErrorMessage = "Invalid request line (version)";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawVer.IndexOf ("HTTP/") != 0) {
|
if (rawVer.IndexOf ("HTTP/") != 0) {
|
||||||
_context.ErrorMessage = "Invalid request line (version)";
|
_context.ErrorMessage = "Invalid request line (version)";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Version ver;
|
Version ver;
|
||||||
|
|
||||||
if (!rawVer.Substring (5).TryCreateVersion (out ver)) {
|
if (!rawVer.Substring (5).TryCreateVersion (out ver)) {
|
||||||
_context.ErrorMessage = "Invalid request line (version)";
|
_context.ErrorMessage = "Invalid request line (version)";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ver.Major < 1) {
|
if (ver.Major < 1) {
|
||||||
_context.ErrorMessage = "Invalid request line (version)";
|
_context.ErrorMessage = "Invalid request line (version)";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!method.IsHttpMethod (ver)) {
|
if (!method.IsHttpMethod (ver)) {
|
||||||
_context.ErrorMessage = "Invalid request line (method)";
|
_context.ErrorMessage = "Invalid request line (method)";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user