diff options
Diffstat (limited to 'chromium/net/server/http_server.cc')
-rw-r--r-- | chromium/net/server/http_server.cc | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/chromium/net/server/http_server.cc b/chromium/net/server/http_server.cc index a51feb84401..f746f066e42 100644 --- a/chromium/net/server/http_server.cc +++ b/chromium/net/server/http_server.cc @@ -47,6 +47,13 @@ void HttpServer::SendOverWebSocket(int connection_id, connection->web_socket_->Send(data); } +void HttpServer::SendRaw(int connection_id, const std::string& data) { + HttpConnection* connection = FindConnection(connection_id); + if (connection == NULL) + return; + connection->Send(data); +} + void HttpServer::SendResponse(int connection_id, const HttpServerResponseInfo& response) { HttpConnection* connection = FindConnection(connection_id); @@ -132,8 +139,10 @@ void HttpServer::DidRead(StreamListenSocket* socket, if (!ParseHeaders(connection, &request, &pos)) break; - std::string connection_header = request.GetHeaderValue("connection"); - if (connection_header == "Upgrade") { + // Sets peer address if exists. + socket->GetPeerAddress(&request.peer); + + if (request.HasHeaderValue("connection", "upgrade")) { connection->web_socket_.reset(WebSocket::CreateWebSocket(connection, request, &pos)); @@ -195,7 +204,7 @@ HttpServer::~HttpServer() { // Input character types. enum header_parse_inputs { - INPUT_SPACE, + INPUT_LWS, INPUT_CR, INPUT_LF, INPUT_COLON, @@ -234,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': @@ -260,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) { @@ -281,10 +292,16 @@ bool HttpServer::ParseHeaders(HttpConnection* connection, buffer.clear(); break; case ST_VALUE: - TrimWhitespaceASCII(buffer, 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; + base::TrimWhitespaceASCII(buffer, base::TRIM_LEADING, &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: |