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

Unified Diff: net/server/http_server.cc

Issue 19637005: Allow HttpServer response to include custom headers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, add back original Send method Created 7 years, 5 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 | « net/server/http_server.h ('k') | net/server/http_server_response_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 b78073983aed08b1e69400e51e2deb819dd39e6f..3d54c4071e7880f95fdc01271a3b775cdea4234a 100644
--- a/net/server/http_server.cc
+++ b/net/server/http_server.cc
@@ -13,6 +13,7 @@
#include "build/build_config.h"
#include "net/server/http_connection.h"
#include "net/server/http_server_request_info.h"
+#include "net/server/http_server_response_info.h"
#include "net/server/web_socket.h"
#include "net/socket/tcp_listen_socket.h"
@@ -45,14 +46,21 @@ void HttpServer::SendOverWebSocket(int connection_id,
connection->web_socket_->Send(data);
}
+void HttpServer::SendResponse(int connection_id,
+ const HttpServerResponseInfo& response) {
+ HttpConnection* connection = FindConnection(connection_id);
+ if (connection == NULL)
+ return;
+ connection->Send(response);
+}
+
void HttpServer::Send(int connection_id,
HttpStatusCode status_code,
const std::string& data,
const std::string& content_type) {
- HttpConnection* connection = FindConnection(connection_id);
- if (connection == NULL)
- return;
- connection->Send(status_code, data, content_type);
+ HttpServerResponseInfo response(status_code);
+ response.SetBody(data, content_type);
+ SendResponse(connection_id, response);
}
void HttpServer::Send200(int connection_id,
@@ -62,11 +70,11 @@ void HttpServer::Send200(int connection_id,
}
void HttpServer::Send404(int connection_id) {
- Send(connection_id, HTTP_NOT_FOUND, std::string(), "text/html");
+ SendResponse(connection_id, HttpServerResponseInfo::CreateFor404());
}
void HttpServer::Send500(int connection_id, const std::string& message) {
- Send(connection_id, HTTP_INTERNAL_SERVER_ERROR, message, "text/html");
+ SendResponse(connection_id, HttpServerResponseInfo::CreateFor500(message));
}
void HttpServer::Close(int connection_id) {
« no previous file with comments | « net/server/http_server.h ('k') | net/server/http_server_response_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698