Skip to content

Commit

Permalink
DevTools: no way to remote debug using ToT build as a client.
Browse files Browse the repository at this point in the history
(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
  • Loading branch information
pfeldman@chromium.org committed Aug 2, 2011
1 parent 33a4aca commit 86c6a0b
Show file tree
Hide file tree
Showing 9 changed files with 653 additions and 234 deletions.
4 changes: 4 additions & 0 deletions net/net.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,10 +1316,14 @@
'../testing/gtest.gyp:gtest',
],
'sources': [
'server/http_connection.cc',
'server/http_connection.h',
'server/http_server.cc',
'server/http_server.h',
'server/http_server_request_info.cc',
'server/http_server_request_info.h',
'server/web_socket.cc',
'server/web_socket.h',
],
},
{
Expand Down
84 changes: 84 additions & 0 deletions net/server/http_connection.cc
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions net/server/http_connection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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.

#ifndef NET_SERVER_HTTP_CONNECTION_H_
#define NET_SERVER_HTTP_CONNECTION_H_
#pragma once

#include <string>

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"

namespace net {

class HttpServer;
class HttpServerRequestInfo;
class ListenSocket;
class WebSocket;

class HttpConnection {
public:
void Send(const std::string& data);
void Send(const char* bytes, int len);
void Send200(const std::string& data, const std::string& content_type);
void Send404();
void Send500(const std::string& message);

void Shift(int num_bytes);

const std::string& recv_data() const { return recv_data_; }
const int id() const { return id_; }

private:
friend class HttpServer;
static int last_id_;

HttpConnection(HttpServer* server, ListenSocket* sock);
~HttpConnection();

void DetachSocket();

HttpServer* server_;
scoped_refptr<ListenSocket> socket_;
scoped_ptr<WebSocket> web_socket_;
std::string recv_data_;
int id_;
DISALLOW_COPY_AND_ASSIGN(HttpConnection);
};

} // namespace net

#endif // NET_SERVER_HTTP_CONNECTION_H_
Loading

0 comments on commit 86c6a0b

Please sign in to comment.