forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
pfeldman@chromium.org
committed
Aug 2, 2011
1 parent
33a4aca
commit 86c6a0b
Showing
9 changed files
with
653 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
Oops, something went wrong.