[Modify] Return bool

This commit is contained in:
sta 2016-01-21 15:37:32 +09:00
parent bcab731cd5
commit 00ea73f331

View File

@ -666,8 +666,8 @@ namespace WebSocketSharp
{ {
_logger.Debug (String.Format ("A request from {0}:\n{1}", _context.UserEndPoint, _context)); _logger.Debug (String.Format ("A request from {0}:\n{1}", _context.UserEndPoint, _context));
var msg = checkIfValidHandshakeRequest (_context); string msg;
if (msg != null) { if (!checkIfValidHandshakeRequest (_context, out msg)) {
sendHttpResponse (createHandshakeCloseResponse (HttpStatusCode.BadRequest)); sendHttpResponse (createHandshakeCloseResponse (HttpStatusCode.BadRequest));
throw new WebSocketException (CloseStatusCode.ProtocolError, msg); throw new WebSocketException (CloseStatusCode.ProtocolError, msg);
} }
@ -698,18 +698,36 @@ namespace WebSocketSharp
} }
// As server // As server
private string checkIfValidHandshakeRequest (WebSocketContext context) private bool checkIfValidHandshakeRequest (WebSocketContext context, out string message)
{ {
message = null;
if (context.RequestUri == null) {
message = "Specifies an invalid Request-URI.";
return false;
}
if (!context.IsWebSocketRequest) {
message = "Not a WebSocket handshake request.";
return false;
}
var headers = context.Headers; var headers = context.Headers;
return context.RequestUri == null if (!validateSecWebSocketKeyHeader (headers["Sec-WebSocket-Key"])) {
? "Specifies an invalid Request-URI." message = "Includes an invalid Sec-WebSocket-Key header.";
: !context.IsWebSocketRequest return false;
? "Not a WebSocket connection request." }
: !validateSecWebSocketKeyHeader (headers["Sec-WebSocket-Key"])
? "Includes an invalid Sec-WebSocket-Key header." if (!validateSecWebSocketVersionClientHeader (headers["Sec-WebSocket-Version"])) {
: !validateSecWebSocketVersionClientHeader (headers["Sec-WebSocket-Version"]) message = "Includes an invalid Sec-WebSocket-Version header.";
? "Includes an invalid Sec-WebSocket-Version header." return false;
: CustomHandshakeRequestChecker (context); }
message = CustomHandshakeRequestChecker (context);
if (message != null)
return false;
return true;
} }
// As client // As client