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

Unified Diff: net/server/http_server.cc

Issue 274813002: HttpServer: Handling of multiple header fields with the same name and multiple values of "Connectio… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: HasHeaderValue always worked as if header_value=="upgrade" Created 6 years, 7 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
« no previous file with comments | « no previous file | net/server/http_server_request_info.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/server/http_server.cc
diff --git a/net/server/http_server.cc b/net/server/http_server.cc
index df77c3672daa423fe54127495aa18b7a4262a104..f746f066e421798b681ac362b8767682d7883a63 100644
--- a/net/server/http_server.cc
+++ b/net/server/http_server.cc
@@ -142,8 +142,7 @@ void HttpServer::DidRead(StreamListenSocket* socket,
// Sets peer address if exists.
socket->GetPeerAddress(&request.peer);
- std::string connection_header = request.GetHeaderValue("connection");
- if (connection_header == "Upgrade") {
+ if (request.HasHeaderValue("connection", "upgrade")) {
connection->web_socket_.reset(WebSocket::CreateWebSocket(connection,
request,
&pos));
@@ -205,7 +204,7 @@ HttpServer::~HttpServer() {
// Input character types.
enum header_parse_inputs {
- INPUT_SPACE,
+ INPUT_LWS,
INPUT_CR,
INPUT_LF,
INPUT_COLON,
@@ -244,7 +243,8 @@ int parser_state[MAX_STATES][MAX_INPUTS] = {
int charToInput(char ch) {
switch(ch) {
case ' ':
- return INPUT_SPACE;
+ case '\t':
+ return INPUT_LWS;
case '\r':
return INPUT_CR;
case '\n':
@@ -270,6 +270,7 @@ bool HttpServer::ParseHeaders(HttpConnection* connection,
int next_state = parser_state[state][input];
bool transition = (next_state != state);
+ HttpServerRequestInfo::HeadersMap::iterator it;
if (transition) {
// Do any actions based on state transitions.
switch (state) {
@@ -292,9 +293,15 @@ bool HttpServer::ParseHeaders(HttpConnection* connection,
break;
case ST_VALUE:
base::TrimWhitespaceASCII(buffer, base::TRIM_LEADING, &header_value);
- // TODO(mbelshe): Deal better with duplicate headers
- DCHECK(info->headers.find(header_name) == info->headers.end());
- info->headers[header_name] = header_value;
+ it = info->headers.find(header_name);
+ // See last paragraph ("Multiple message-header fields...")
+ // of www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
+ if (it == info->headers.end()) {
+ info->headers[header_name] = header_value;
+ } else {
+ it->second.append(",");
+ it->second.append(header_value);
+ }
buffer.clear();
break;
case ST_SEPARATOR:
« no previous file with comments | « no previous file | net/server/http_server_request_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698