Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Unified Diff: net/server/http_server.cc

Issue 2314073003: Handle non-HTTP/1.1 requests more gracefully in net::HttpServer. (Closed)
Patch Set: Close the connection on a parsing error Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/server/http_server.cc
diff --git a/net/server/http_server.cc b/net/server/http_server.cc
index 08d0706c3c73a870c4badbd54938355440087575..10ed7e81e5ac29b8f686bbd80e2a7c5a7a4bcb7a 100644
--- a/net/server/http_server.cc
+++ b/net/server/http_server.cc
@@ -230,8 +230,11 @@ int HttpServer::HandleReadResult(HttpConnection* connection, int rv) {
HttpServerRequestInfo request;
size_t pos = 0;
- if (!ParseHeaders(read_buf->StartOfBuffer(), read_buf->GetSize(),
- &request, &pos)) {
+ if (!ParseHeaders(connection->id(), read_buf->StartOfBuffer(),
+ read_buf->GetSize(), &request, &pos)) {
+ // Check if a parsing error has caused the connection to close.
+ if (HasClosedConnection(connection))
+ return ERR_CONNECTION_CLOSED;
break;
}
@@ -378,7 +381,8 @@ int charToInput(char ch) {
} // namespace
-bool HttpServer::ParseHeaders(const char* data,
+bool HttpServer::ParseHeaders(int connection_id,
+ const char* data,
size_t data_len,
HttpServerRequestInfo* info,
size_t* ppos) {
@@ -406,8 +410,10 @@ bool HttpServer::ParseHeaders(const char* data,
buffer.clear();
break;
case ST_PROTO:
- // TODO(mbelshe): Deal better with parsing protocol.
- DCHECK(buffer == "HTTP/1.1");
+ if (buffer != "HTTP/1.1") {
+ LOG(ERROR) << "Ignoring request with protocol: " << buffer;
+ next_state = ST_ERR;
+ }
buffer.clear();
break;
case ST_NAME:
@@ -445,6 +451,7 @@ bool HttpServer::ParseHeaders(const char* data,
DCHECK(input == INPUT_LF);
return true;
case ST_ERR:
+ Close(connection_id);
return false;
}
}

Powered by Google App Engine
This is Rietveld 408576698