[Modify] Polish it

This commit is contained in:
sta 2021-08-31 19:36:49 +09:00
parent f11a8c30c2
commit 1a5f82ce01

View File

@ -784,34 +784,42 @@ namespace WebSocketSharp.Server
{ {
if (!authenticateClient (context)) { if (!authenticateClient (context)) {
context.Close (HttpStatusCode.Forbidden); context.Close (HttpStatusCode.Forbidden);
return; return;
} }
var uri = context.RequestUri; var uri = context.RequestUri;
if (uri == null) { if (uri == null) {
context.Close (HttpStatusCode.BadRequest); context.Close (HttpStatusCode.BadRequest);
return; return;
} }
if (!_allowForwardedRequest) { if (!_allowForwardedRequest) {
if (uri.Port != _port) { if (uri.Port != _port) {
context.Close (HttpStatusCode.BadRequest); context.Close (HttpStatusCode.BadRequest);
return; return;
} }
if (!checkHostNameForRequest (uri.DnsSafeHost)) { if (!checkHostNameForRequest (uri.DnsSafeHost)) {
context.Close (HttpStatusCode.NotFound); context.Close (HttpStatusCode.NotFound);
return; return;
} }
} }
var path = uri.AbsolutePath; var path = uri.AbsolutePath;
if (path.IndexOfAny (new[] { '%', '+' }) > -1) if (path.IndexOfAny (new[] { '%', '+' }) > -1)
path = HttpUtility.UrlDecode (path, Encoding.UTF8); path = HttpUtility.UrlDecode (path, Encoding.UTF8);
WebSocketServiceHost host; WebSocketServiceHost host;
if (!_services.InternalTryGetServiceHost (path, out host)) { if (!_services.InternalTryGetServiceHost (path, out host)) {
context.Close (HttpStatusCode.NotImplemented); context.Close (HttpStatusCode.NotImplemented);
return; return;
} }