Skip to content

Commit

Permalink
Return 400 Bad Request when "Host" header is null
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Kellogg committed Dec 11, 2014
1 parent 2b48a12 commit f094b4d
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ class RequestHandler(server: WebServer, routes: PartialFunction[SockoEvent, Unit
* @param e Message to process
*/
override def channelRead(ctx: ChannelHandlerContext, e: AnyRef) {
def isInvalid(httpRequest: HttpRequest): Boolean = HttpHeaders.getHost(httpRequest) == null

e match {
case httpRequest: FullHttpRequest if isInvalid(httpRequest) =>
writeErrorResponse(ctx, HttpResponseStatus.BAD_REQUEST, new NullPointerException)

case httpRequest: FullHttpRequest =>
val event = HttpRequestEvent(ctx, httpRequest, httpConfig)

Expand All @@ -125,6 +130,9 @@ class RequestHandler(server: WebServer, routes: PartialFunction[SockoEvent, Unit
routes(event)
}

case httpRequest: HttpRequest if isInvalid(httpRequest) =>
writeErrorResponse(ctx, HttpResponseStatus.BAD_REQUEST, new NullPointerException)

case httpRequest: HttpRequest =>
val event = HttpRequestEvent(ctx, httpRequest, httpConfig)

Expand Down

0 comments on commit f094b4d

Please sign in to comment.