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

Unified Diff: net/server/http_server.cc

Issue 2314073003: Handle non-HTTP/1.1 requests more gracefully in net::HttpServer. (Closed)
Patch Set: More tests 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 c362e1b080f40b749d973fa2bbf34e0624af4a87..38ec2328d6a7369b7adbd5d381c6b4fe2c8226f9 100644
--- a/net/server/http_server.cc
+++ b/net/server/http_server.cc
@@ -232,6 +232,12 @@ int HttpServer::HandleReadResult(HttpConnection* connection, int rv) {
size_t pos = 0;
if (!ParseHeaders(read_buf->StartOfBuffer(), read_buf->GetSize(),
&request, &pos)) {
+ // An error has occured. Close the connection.
+ Close(connection->id());
+ return ERR_CONNECTION_CLOSED;
+ } else if (!pos) {
+ // If pos is 0, we read all the data in read_buf, but haven't yet finished
mmenke 2016/09/15 17:40:12 nit: avoid "we" in comments, due to ambiguity ("W
slan 2016/09/16 22:35:30 Done.
+ // parsing the headers. Continue parsing when more data rolls in.
break;
}
@@ -405,8 +411,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) << "Cannot handle request with protocol: " << buffer;
+ next_state = ST_ERR;
+ }
buffer.clear();
break;
case ST_NAME:
@@ -448,8 +456,10 @@ bool HttpServer::ParseHeaders(const char* data,
}
}
}
- // No more characters, but we haven't finished parsing yet.
- return false;
+ // No more characters, but we haven't finished parsing yet. Signal this to
+ // the caller by setting |pos| to zero.
+ pos = 0;
+ return true;
}
HttpConnection* HttpServer::FindConnection(int connection_id) {

Powered by Google App Engine
This is Rietveld 408576698