summaryrefslogtreecommitdiffstats
path: root/net/server/http_connection.cc
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 19:49:25 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 19:49:25 +0000
commit86c6a0b5a5c08aa5ed1244e4a4fc2796393ad5a5 (patch)
tree14d8273e6669c54599466a7708b437cd51facb03 /net/server/http_connection.cc
parent33a4aca7c65ed0bb2636615ef5e5c83cf50ff6a0 (diff)
downloadchromium_src-86c6a0b5a5c08aa5ed1244e4a4fc2796393ad5a5.zip
chromium_src-86c6a0b5a5c08aa5ed1244e4a4fc2796393ad5a5.tar.gz
chromium_src-86c6a0b5a5c08aa5ed1244e4a4fc2796393ad5a5.tar.bz2
DevTools: no way to remote debug using ToT build as a client.
(rebaselined and brushed up loislo's http://codereview.chromium.org/7482041) BUG=90743 TEST= Review URL: http://codereview.chromium.org/7540023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95138 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/server/http_connection.cc')
-rw-r--r--net/server/http_connection.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/net/server/http_connection.cc b/net/server/http_connection.cc
new file mode 100644
index 0000000..3404c68
--- /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::last_id_ = 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_ = last_id_++;
+}
+
+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