OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/server/http_connection.h" | 5 #include "net/server/http_connection.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "net/base/listen_socket.h" | 9 #include "net/base/stream_listen_socket.h" |
10 #include "net/server/http_server.h" | 10 #include "net/server/http_server.h" |
11 #include "net/server/web_socket.h" | 11 #include "net/server/web_socket.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 int HttpConnection::last_id_ = 0; | 15 int HttpConnection::last_id_ = 0; |
16 | 16 |
17 void HttpConnection::Send(const std::string& data) { | 17 void HttpConnection::Send(const std::string& data) { |
18 if (!socket_) | 18 if (!socket_) |
19 return; | 19 return; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 socket_->Send(base::StringPrintf( | 55 socket_->Send(base::StringPrintf( |
56 "HTTP/1.1 500 Internal Error\r\n" | 56 "HTTP/1.1 500 Internal Error\r\n" |
57 "Content-Type:text/html\r\n" | 57 "Content-Type:text/html\r\n" |
58 "Content-Length:%d\r\n" | 58 "Content-Length:%d\r\n" |
59 "\r\n" | 59 "\r\n" |
60 "%s", | 60 "%s", |
61 static_cast<int>(message.length()), | 61 static_cast<int>(message.length()), |
62 message.c_str())); | 62 message.c_str())); |
63 } | 63 } |
64 | 64 |
65 HttpConnection::HttpConnection(HttpServer* server, ListenSocket* sock) | 65 HttpConnection::HttpConnection(HttpServer* server, StreamListenSocket* sock) |
66 : server_(server), | 66 : server_(server), |
67 socket_(sock) { | 67 socket_(sock) { |
68 id_ = last_id_++; | 68 id_ = last_id_++; |
69 } | 69 } |
70 | 70 |
71 HttpConnection::~HttpConnection() { | 71 HttpConnection::~HttpConnection() { |
72 DetachSocket(); | 72 DetachSocket(); |
73 server_->delegate_->OnClose(id_); | 73 server_->delegate_->OnClose(id_); |
74 } | 74 } |
75 | 75 |
76 void HttpConnection::DetachSocket() { | 76 void HttpConnection::DetachSocket() { |
77 socket_ = NULL; | 77 socket_ = NULL; |
78 } | 78 } |
79 | 79 |
80 void HttpConnection::Shift(int num_bytes) { | 80 void HttpConnection::Shift(int num_bytes) { |
81 recv_data_ = recv_data_.substr(num_bytes); | 81 recv_data_ = recv_data_.substr(num_bytes); |
82 } | 82 } |
83 | 83 |
84 } // namespace net | 84 } // namespace net |
OLD | NEW |