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

Unified Diff: net/server/http_connection.cc

Issue 7540023: DevTools: no way to remote debug using ToT build as a client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments addressed. Created 9 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
Index: net/server/http_connection.cc
diff --git a/net/server/http_connection.cc b/net/server/http_connection.cc
new file mode 100644
index 0000000000000000000000000000000000000000..432d4c23a0cb13aa781aea5bc24ceec7221930d8
--- /dev/null
+++ b/net/server/http_connection.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/server/http_connection.h"
+
+#include "base/string_util.h"
+#include "base/stringprintf.h"
+#include "net/base/listen_socket.h"
+#include "net/server/http_server.h"
+#include "net/server/web_socket.h"
+
+namespace net {
+
+int HttpConnection::lastId_ = 0;
+
+void HttpConnection::Send(const std::string& data) {
+ if (!socket_)
+ return;
+ socket_->Send(data);
+}
+
+void HttpConnection::Send(const char* bytes, int len) {
+ if (!socket_)
+ return;
+ socket_->Send(bytes, len);
+}
+
+void HttpConnection::Send200(const std::string& data,
+ const std::string& content_type) {
+ if (!socket_)
+ return;
+ socket_->Send(base::StringPrintf(
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Type:%s\r\n"
+ "Content-Length:%d\r\n"
+ "\r\n",
+ content_type.c_str(),
+ static_cast<int>(data.length())));
+ socket_->Send(data);
+}
+
+void HttpConnection::Send404() {
+ if (!socket_)
+ return;
+ socket_->Send(
+ "HTTP/1.1 404 Not Found\r\n"
+ "Content-Length: 0\r\n"
+ "\r\n");
+}
+
+void HttpConnection::Send500(const std::string& message) {
+ if (!socket_)
+ return;
+ socket_->Send(base::StringPrintf(
+ "HTTP/1.1 500 Internal Error\r\n"
+ "Content-Type:text/html\r\n"
+ "Content-Length:%d\r\n"
+ "\r\n"
+ "%s",
+ static_cast<int>(message.length()),
+ message.c_str()));
+}
+
+HttpConnection::HttpConnection(HttpServer* server, ListenSocket* sock)
+ : server_(server),
+ socket_(sock) {
+ id_ = lastId_++;
+}
+
+HttpConnection::~HttpConnection() {
+ DetachSocket();
+ server_->delegate_->OnClose(id_);
+}
+
+void HttpConnection::DetachSocket() {
+ socket_ = NULL;
+}
+
+void HttpConnection::Shift(int num_bytes) {
+ recv_data_ = recv_data_.substr(num_bytes);
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698