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

Unified Diff: net/server/http_server.cc

Issue 181063006: Gets the peer address (if available) in server requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Diff upload failed Created 6 years, 10 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') | net/socket/stream_listen_socket.cc » ('J')
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 a51feb84401e4ebf7c3ce370e423ee04ab34be89..bf6c571a5c9c1bd1520a66b9f4068dbbb40fe144 100644
--- a/net/server/http_server.cc
+++ b/net/server/http_server.cc
@@ -12,6 +12,7 @@
#include "base/strings/stringprintf.h"
#include "base/sys_byteorder.h"
#include "build/build_config.h"
+#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/server/http_connection.h"
#include "net/server/http_server_request_info.h"
@@ -132,6 +133,12 @@ void HttpServer::DidRead(StreamListenSocket* socket,
if (!ParseHeaders(connection, &request, &pos))
break;
+ // Sets peer address if exists.
+ IPEndPoint peer;
+ if (socket->GetPeerAddress(&peer) == OK) {
+ request.peer = peer;
Ryan Sleevi 2014/03/11 01:32:43 Why not socket->GetPeerAddress(&request.peer)? Se
gunsch 2014/03/17 16:57:15 Done.
+ }
+
std::string connection_header = request.GetHeaderValue("connection");
if (connection_header == "Upgrade") {
connection->web_socket_.reset(WebSocket::CreateWebSocket(connection,
@@ -145,6 +152,13 @@ void HttpServer::DidRead(StreamListenSocket* socket,
continue;
}
+ // Rejects non "HTTP/1.1" requests and terminate connection.
+ if (request.proto != "HTTP/1.1") {
+ connection->Send(HttpServerResponseInfo(HTTP_NOT_IMPLEMENTED));
+ Close(connection->id());
+ break;
+ }
Ryan Sleevi 2014/03/11 01:32:43 Unrelated?
gunsch 2014/03/17 16:57:15 This was in our local changes to this class, but I
+
const char kContentLength[] = "content-length";
if (request.headers.count(kContentLength)) {
size_t content_length = 0;
@@ -272,8 +286,7 @@ bool HttpServer::ParseHeaders(HttpConnection* connection,
buffer.clear();
break;
case ST_PROTO:
- // TODO(mbelshe): Deal better with parsing protocol.
- DCHECK(buffer == "HTTP/1.1");
+ info->proto = buffer;
Ryan Sleevi 2014/03/11 01:32:43 ditto
gunsch 2014/03/17 16:57:15 Done.
buffer.clear();
break;
case ST_NAME:
« no previous file with comments | « no previous file | net/server/http_server_request_info.h » ('j') | net/socket/stream_listen_socket.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698