summaryrefslogtreecommitdiff
path: root/chromium/net/server
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-03 13:42:47 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-05-15 10:27:51 +0000
commit8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec (patch)
treed29d987c4d7b173cf853279b79a51598f104b403 /chromium/net/server
parent830c9e163d31a9180fadca926b3e1d7dfffb5021 (diff)
downloadqtwebengine-chromium-8c5c43c7b138c9b4b0bf56d946e61d3bbc111bec.tar.gz
BASELINE: Update Chromium to 66.0.3359.156
Change-Id: I0c9831ad39911a086b6377b16f995ad75a51e441 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'chromium/net/server')
-rw-r--r--chromium/net/server/http_server.cc94
-rw-r--r--chromium/net/server/http_server.h36
-rw-r--r--chromium/net/server/http_server_fuzzer.cc9
-rw-r--r--chromium/net/server/http_server_unittest.cc20
-rw-r--r--chromium/net/server/web_socket.cc23
-rw-r--r--chromium/net/server/web_socket.h10
6 files changed, 136 insertions, 56 deletions
diff --git a/chromium/net/server/http_server.cc b/chromium/net/server/http_server.cc
index 142c2e36d0c..f0fc3c34a0a 100644
--- a/chromium/net/server/http_server.cc
+++ b/chromium/net/server/http_server.cc
@@ -27,6 +27,31 @@
namespace net {
+namespace {
+
+constexpr NetworkTrafficAnnotationTag
+ kHttpServerErrorResponseTrafficAnnotation =
+ DefineNetworkTrafficAnnotation("http_server_error_response",
+ R"(
+ semantics {
+ sender: "HTTP Server"
+ description: "Error response from the built-in HTTP server."
+ trigger: "Sending a request to the HTTP server that it can't handle."
+ data: "A 500 error code."
+ destination: OTHER
+ destination_other: "Any destination the consumer selects."
+ }
+ policy {
+ cookies_allowed: NO
+ setting:
+ "This request cannot be disabled in settings. However it will never "
+ "be made unless user activates an HTTP server."
+ policy_exception_justification:
+ "Not implemented, not used if HTTP Server is not activated."
+ })");
+
+} // namespace
+
HttpServer::HttpServer(std::unique_ptr<ServerSocket> server_socket,
HttpServer::Delegate* delegate)
: server_socket_(std::move(server_socket)),
@@ -45,60 +70,73 @@ HttpServer::~HttpServer() = default;
void HttpServer::AcceptWebSocket(
int connection_id,
- const HttpServerRequestInfo& request) {
+ const HttpServerRequestInfo& request,
+ NetworkTrafficAnnotationTag traffic_annotation) {
HttpConnection* connection = FindConnection(connection_id);
if (connection == NULL)
return;
DCHECK(connection->web_socket());
- connection->web_socket()->Accept(request);
+ connection->web_socket()->Accept(request, traffic_annotation);
}
-void HttpServer::SendOverWebSocket(int connection_id,
- const std::string& data) {
+void HttpServer::SendOverWebSocket(
+ int connection_id,
+ const std::string& data,
+ NetworkTrafficAnnotationTag traffic_annotation) {
HttpConnection* connection = FindConnection(connection_id);
if (connection == NULL)
return;
DCHECK(connection->web_socket());
- connection->web_socket()->Send(data);
+ connection->web_socket()->Send(data, traffic_annotation);
}
-void HttpServer::SendRaw(int connection_id, const std::string& data) {
+void HttpServer::SendRaw(int connection_id,
+ const std::string& data,
+ NetworkTrafficAnnotationTag traffic_annotation) {
HttpConnection* connection = FindConnection(connection_id);
if (connection == NULL)
return;
bool writing_in_progress = !connection->write_buf()->IsEmpty();
if (connection->write_buf()->Append(data) && !writing_in_progress)
- DoWriteLoop(connection);
+ DoWriteLoop(connection, traffic_annotation);
}
void HttpServer::SendResponse(int connection_id,
- const HttpServerResponseInfo& response) {
- SendRaw(connection_id, response.Serialize());
+ const HttpServerResponseInfo& response,
+ NetworkTrafficAnnotationTag traffic_annotation) {
+ SendRaw(connection_id, response.Serialize(), traffic_annotation);
}
void HttpServer::Send(int connection_id,
HttpStatusCode status_code,
const std::string& data,
- const std::string& content_type) {
+ const std::string& content_type,
+ NetworkTrafficAnnotationTag traffic_annotation) {
HttpServerResponseInfo response(status_code);
response.SetContentHeaders(data.size(), content_type);
- SendResponse(connection_id, response);
- SendRaw(connection_id, data);
+ SendResponse(connection_id, response, traffic_annotation);
+ SendRaw(connection_id, data, traffic_annotation);
}
void HttpServer::Send200(int connection_id,
const std::string& data,
- const std::string& content_type) {
- Send(connection_id, HTTP_OK, data, content_type);
+ const std::string& content_type,
+ NetworkTrafficAnnotationTag traffic_annotation) {
+ Send(connection_id, HTTP_OK, data, content_type, traffic_annotation);
}
-void HttpServer::Send404(int connection_id) {
- SendResponse(connection_id, HttpServerResponseInfo::CreateFor404());
+void HttpServer::Send404(int connection_id,
+ NetworkTrafficAnnotationTag traffic_annotation) {
+ SendResponse(connection_id, HttpServerResponseInfo::CreateFor404(),
+ traffic_annotation);
}
-void HttpServer::Send500(int connection_id, const std::string& message) {
- SendResponse(connection_id, HttpServerResponseInfo::CreateFor500(message));
+void HttpServer::Send500(int connection_id,
+ const std::string& message,
+ NetworkTrafficAnnotationTag traffic_annotation) {
+ SendResponse(connection_id, HttpServerResponseInfo::CreateFor500(message),
+ traffic_annotation);
}
void HttpServer::Close(int connection_id) {
@@ -261,7 +299,8 @@ int HttpServer::HandleReadResult(HttpConnection* connection, int rv) {
SendResponse(connection->id(),
HttpServerResponseInfo::CreateFor500(
"request content-length too big or unknown: " +
- request.GetHeaderValue(kContentLength)));
+ request.GetHeaderValue(kContentLength)),
+ kHttpServerErrorResponseTrafficAnnotation);
Close(connection->id());
return ERR_CONNECTION_CLOSED;
}
@@ -281,28 +320,33 @@ int HttpServer::HandleReadResult(HttpConnection* connection, int rv) {
return OK;
}
-void HttpServer::DoWriteLoop(HttpConnection* connection) {
+void HttpServer::DoWriteLoop(HttpConnection* connection,
+ NetworkTrafficAnnotationTag traffic_annotation) {
int rv = OK;
HttpConnection::QueuedWriteIOBuffer* write_buf = connection->write_buf();
while (rv == OK && write_buf->GetSizeToWrite() > 0) {
rv = connection->socket()->Write(
- write_buf,
- write_buf->GetSizeToWrite(),
+ write_buf, write_buf->GetSizeToWrite(),
base::Bind(&HttpServer::OnWriteCompleted,
- weak_ptr_factory_.GetWeakPtr(), connection->id()));
+ weak_ptr_factory_.GetWeakPtr(), connection->id(),
+ traffic_annotation),
+ traffic_annotation);
if (rv == ERR_IO_PENDING || rv == OK)
return;
rv = HandleWriteResult(connection, rv);
}
}
-void HttpServer::OnWriteCompleted(int connection_id, int rv) {
+void HttpServer::OnWriteCompleted(
+ int connection_id,
+ NetworkTrafficAnnotationTag traffic_annotation,
+ int rv) {
HttpConnection* connection = FindConnection(connection_id);
if (!connection) // It might be closed right before by read error.
return;
if (HandleWriteResult(connection, rv) == OK)
- DoWriteLoop(connection);
+ DoWriteLoop(connection, traffic_annotation);
}
int HttpServer::HandleWriteResult(HttpConnection* connection, int rv) {
diff --git a/chromium/net/server/http_server.h b/chromium/net/server/http_server.h
index dda1a5c7c04..8115016c14c 100644
--- a/chromium/net/server/http_server.h
+++ b/chromium/net/server/http_server.h
@@ -15,6 +15,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "net/http/http_status_code.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
namespace net {
@@ -52,23 +53,35 @@ class HttpServer {
~HttpServer();
void AcceptWebSocket(int connection_id,
- const HttpServerRequestInfo& request);
- void SendOverWebSocket(int connection_id, const std::string& data);
+ const HttpServerRequestInfo& request,
+ NetworkTrafficAnnotationTag traffic_annotation);
+ void SendOverWebSocket(int connection_id,
+ const std::string& data,
+ NetworkTrafficAnnotationTag traffic_annotation);
// Sends the provided data directly to the given connection. No validation is
// performed that data constitutes a valid HTTP response. A valid HTTP
// response may be split across multiple calls to SendRaw.
- void SendRaw(int connection_id, const std::string& data);
+ void SendRaw(int connection_id,
+ const std::string& data,
+ NetworkTrafficAnnotationTag traffic_annotation);
// TODO(byungchul): Consider replacing function name with SendResponseInfo
- void SendResponse(int connection_id, const HttpServerResponseInfo& response);
+ void SendResponse(int connection_id,
+ const HttpServerResponseInfo& response,
+ NetworkTrafficAnnotationTag traffic_annotation);
void Send(int connection_id,
HttpStatusCode status_code,
const std::string& data,
- const std::string& mime_type);
+ const std::string& mime_type,
+ NetworkTrafficAnnotationTag traffic_annotation);
void Send200(int connection_id,
const std::string& data,
- const std::string& mime_type);
- void Send404(int connection_id);
- void Send500(int connection_id, const std::string& message);
+ const std::string& mime_type,
+ NetworkTrafficAnnotationTag traffic_annotation);
+ void Send404(int connection_id,
+ NetworkTrafficAnnotationTag traffic_annotation);
+ void Send500(int connection_id,
+ const std::string& message,
+ NetworkTrafficAnnotationTag traffic_annotation);
void Close(int connection_id);
@@ -89,8 +102,11 @@ class HttpServer {
void OnReadCompleted(int connection_id, int rv);
int HandleReadResult(HttpConnection* connection, int rv);
- void DoWriteLoop(HttpConnection* connection);
- void OnWriteCompleted(int connection_id, int rv);
+ void DoWriteLoop(HttpConnection* connection,
+ NetworkTrafficAnnotationTag traffic_annotation);
+ void OnWriteCompleted(int connection_id,
+ NetworkTrafficAnnotationTag traffic_annotation,
+ int rv);
int HandleWriteResult(HttpConnection* connection, int rv);
// Expects the raw data to be stored in recv_data_. If parsing is successful,
diff --git a/chromium/net/server/http_server_fuzzer.cc b/chromium/net/server/http_server_fuzzer.cc
index f9af04fd439..c301a06d088 100644
--- a/chromium/net/server/http_server_fuzzer.cc
+++ b/chromium/net/server/http_server_fuzzer.cc
@@ -10,6 +10,7 @@
#include "net/log/test_net_log.h"
#include "net/server/http_server.h"
#include "net/socket/fuzzed_server_socket.h"
+#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
namespace {
@@ -39,7 +40,7 @@ class WaitTillHttpCloseDelegate : public net::HttpServer::Delegate {
if (action_flags_ & REPLY_TO_MESSAGE) {
server_->Send200(connection_id,
data_provider_->ConsumeRandomLengthString(64),
- "text/html");
+ "text/html", TRAFFIC_ANNOTATION_FOR_TESTS);
}
}
@@ -51,7 +52,8 @@ class WaitTillHttpCloseDelegate : public net::HttpServer::Delegate {
}
if (action_flags_ & ACCEPT_WEBSOCKET)
- server_->AcceptWebSocket(connection_id, info);
+ server_->AcceptWebSocket(connection_id, info,
+ TRAFFIC_ANNOTATION_FOR_TESTS);
}
void OnWebSocketMessage(int connection_id, const std::string& data) override {
@@ -62,7 +64,8 @@ class WaitTillHttpCloseDelegate : public net::HttpServer::Delegate {
if (action_flags_ & REPLY_TO_MESSAGE) {
server_->SendOverWebSocket(connection_id,
- data_provider_->ConsumeRandomLengthString(64));
+ data_provider_->ConsumeRandomLengthString(64),
+ TRAFFIC_ANNOTATION_FOR_TESTS);
}
}
diff --git a/chromium/net/server/http_server_unittest.cc b/chromium/net/server/http_server_unittest.cc
index aca53999a12..f1045ae5700 100644
--- a/chromium/net/server/http_server_unittest.cc
+++ b/chromium/net/server/http_server_unittest.cc
@@ -487,7 +487,8 @@ TEST_F(HttpServerTest, Send200) {
ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk());
client.Send("GET /test HTTP/1.1\r\n\r\n");
RunUntilRequestsReceived(1);
- server_->Send200(GetConnectionId(0), "Response!", "text/plain");
+ server_->Send200(GetConnectionId(0), "Response!", "text/plain",
+ TRAFFIC_ANNOTATION_FOR_TESTS);
std::string response;
ASSERT_TRUE(client.ReadResponse(&response));
@@ -502,9 +503,12 @@ TEST_F(HttpServerTest, SendRaw) {
ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk());
client.Send("GET /test HTTP/1.1\r\n\r\n");
RunUntilRequestsReceived(1);
- server_->SendRaw(GetConnectionId(0), "Raw Data ");
- server_->SendRaw(GetConnectionId(0), "More Data");
- server_->SendRaw(GetConnectionId(0), "Third Piece of Data");
+ server_->SendRaw(GetConnectionId(0), "Raw Data ",
+ TRAFFIC_ANNOTATION_FOR_TESTS);
+ server_->SendRaw(GetConnectionId(0), "More Data",
+ TRAFFIC_ANNOTATION_FOR_TESTS);
+ server_->SendRaw(GetConnectionId(0), "Third Piece of Data",
+ TRAFFIC_ANNOTATION_FOR_TESTS);
const std::string expected_response("Raw Data More DataThird Piece of Data");
std::string response;
@@ -671,7 +675,8 @@ TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) {
ASSERT_EQ(body, GetRequest(0).data);
int client_connection_id = GetConnectionId(0);
- server_->Send200(client_connection_id, "Content for /test", "text/plain");
+ server_->Send200(client_connection_id, "Content for /test", "text/plain",
+ TRAFFIC_ANNOTATION_FOR_TESTS);
std::string response1;
ASSERT_TRUE(client.ReadResponse(&response1));
ASSERT_TRUE(base::StartsWith(response1, "HTTP/1.1 200 OK",
@@ -684,7 +689,7 @@ TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) {
ASSERT_EQ("/test2", GetRequest(1).path);
ASSERT_EQ(client_connection_id, GetConnectionId(1));
- server_->Send404(client_connection_id);
+ server_->Send404(client_connection_id, TRAFFIC_ANNOTATION_FOR_TESTS);
std::string response2;
ASSERT_TRUE(client.ReadResponse(&response2));
ASSERT_TRUE(base::StartsWith(response2, "HTTP/1.1 404 Not Found",
@@ -695,7 +700,8 @@ TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) {
ASSERT_EQ("/test3", GetRequest(2).path);
ASSERT_EQ(client_connection_id, GetConnectionId(2));
- server_->Send200(client_connection_id, "Content for /test3", "text/plain");
+ server_->Send200(client_connection_id, "Content for /test3", "text/plain",
+ TRAFFIC_ANNOTATION_FOR_TESTS);
std::string response3;
ASSERT_TRUE(client.ReadResponse(&response3));
ASSERT_TRUE(base::StartsWith(response3, "HTTP/1.1 200 OK",
diff --git a/chromium/net/server/web_socket.cc b/chromium/net/server/web_socket.cc
index 59879e67319..c3b7cf59e70 100644
--- a/chromium/net/server/web_socket.cc
+++ b/chromium/net/server/web_socket.cc
@@ -56,10 +56,12 @@ WebSocket::WebSocket(HttpServer* server, HttpConnection* connection)
WebSocket::~WebSocket() = default;
-void WebSocket::Accept(const HttpServerRequestInfo& request) {
+void WebSocket::Accept(const HttpServerRequestInfo& request,
+ const NetworkTrafficAnnotationTag traffic_annotation) {
std::string version = request.GetHeaderValue("sec-websocket-version");
if (version != "8" && version != "13") {
- SendErrorResponse("Invalid request format. The version is not valid.");
+ SendErrorResponse("Invalid request format. The version is not valid.",
+ traffic_annotation);
return;
}
@@ -67,7 +69,8 @@ void WebSocket::Accept(const HttpServerRequestInfo& request) {
if (key.empty()) {
SendErrorResponse(
"Invalid request format. Sec-WebSocket-Key is empty or isn't "
- "specified.");
+ "specified.",
+ traffic_annotation);
return;
}
std::string encoded_hash;
@@ -91,7 +94,8 @@ void WebSocket::Accept(const HttpServerRequestInfo& request) {
}
}
server_->SendRaw(connection_->id(),
- ValidResponseString(encoded_hash, response_extensions));
+ ValidResponseString(encoded_hash, response_extensions),
+ traffic_annotation);
}
WebSocket::ParseResult WebSocket::Read(std::string* message) {
@@ -120,12 +124,13 @@ WebSocket::ParseResult WebSocket::Read(std::string* message) {
return result;
}
-void WebSocket::Send(const std::string& message) {
+void WebSocket::Send(const std::string& message,
+ const NetworkTrafficAnnotationTag traffic_annotation) {
if (closed_)
return;
std::string encoded;
encoder_->EncodeFrame(message, 0, &encoded);
- server_->SendRaw(connection_->id(), encoded);
+ server_->SendRaw(connection_->id(), encoded, traffic_annotation);
}
void WebSocket::Fail() {
@@ -134,11 +139,13 @@ void WebSocket::Fail() {
server_->Close(connection_->id());
}
-void WebSocket::SendErrorResponse(const std::string& message) {
+void WebSocket::SendErrorResponse(
+ const std::string& message,
+ const NetworkTrafficAnnotationTag traffic_annotation) {
if (closed_)
return;
closed_ = true;
- server_->Send500(connection_->id(), message);
+ server_->Send500(connection_->id(), message, traffic_annotation);
}
} // namespace net
diff --git a/chromium/net/server/web_socket.h b/chromium/net/server/web_socket.h
index aa01f11e163..6d57a7df747 100644
--- a/chromium/net/server/web_socket.h
+++ b/chromium/net/server/web_socket.h
@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/strings/string_piece.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
namespace net {
@@ -29,14 +30,17 @@ class WebSocket final {
WebSocket(HttpServer* server, HttpConnection* connection);
- void Accept(const HttpServerRequestInfo& request);
+ void Accept(const HttpServerRequestInfo& request,
+ const NetworkTrafficAnnotationTag traffic_annotation);
ParseResult Read(std::string* message);
- void Send(const std::string& message);
+ void Send(const std::string& message,
+ const NetworkTrafficAnnotationTag traffic_annotation);
~WebSocket();
private:
void Fail();
- void SendErrorResponse(const std::string& message);
+ void SendErrorResponse(const std::string& message,
+ const NetworkTrafficAnnotationTag traffic_annotation);
HttpServer* const server_;
HttpConnection* const connection_;