OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_ | 5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_ |
6 #define NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_ | 6 #define NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "net/test/embedded_test_server/http_request.h" | 12 #include "net/test/embedded_test_server/http_request.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
| 15 |
15 class StreamListenSocket; | 16 class StreamListenSocket; |
16 } | |
17 | 17 |
18 namespace google_apis { | |
19 namespace test_server { | 18 namespace test_server { |
20 | 19 |
21 class HttpConnection; | 20 class HttpConnection; |
22 class HttpResponse; | 21 class HttpResponse; |
23 | 22 |
24 // Calblack called when a request is parsed. Response should be sent | 23 // Calblack called when a request is parsed. Response should be sent |
25 // using HttpConnection::SendResponse() on the |connection| argument. | 24 // using HttpConnection::SendResponse() on the |connection| argument. |
26 typedef base::Callback<void(HttpConnection* connection, | 25 typedef base::Callback<void(HttpConnection* connection, |
27 scoped_ptr<HttpRequest> request)> | 26 scoped_ptr<HttpRequest> request)> |
28 HandleRequestCallback; | 27 HandleRequestCallback; |
29 | 28 |
30 // Wraps the connection socket. Accepts incoming data and sends responses. | 29 // Wraps the connection socket. Accepts incoming data and sends responses. |
31 // If a valid request is parsed, then |callback_| is invoked. | 30 // If a valid request is parsed, then |callback_| is invoked. |
32 class HttpConnection { | 31 class HttpConnection { |
33 public: | 32 public: |
34 HttpConnection(net::StreamListenSocket* socket, | 33 HttpConnection(StreamListenSocket* socket, |
35 const HandleRequestCallback& callback); | 34 const HandleRequestCallback& callback); |
36 ~HttpConnection(); | 35 ~HttpConnection(); |
37 | 36 |
38 // Sends the HTTP response to the client. | 37 // Sends the HTTP response to the client. |
39 void SendResponse(scoped_ptr<HttpResponse> response) const; | 38 void SendResponse(scoped_ptr<HttpResponse> response) const; |
40 | 39 |
41 private: | 40 private: |
42 friend class HttpServer; | 41 friend class EmbeddedTestServer; |
43 | 42 |
44 // Accepts raw chunk of data from the client. Internally, passes it to the | 43 // Accepts raw chunk of data from the client. Internally, passes it to the |
45 // HttpRequestParser class. If a request is parsed, then |callback_| is | 44 // HttpRequestParser class. If a request is parsed, then |callback_| is |
46 // called. | 45 // called. |
47 void ReceiveData(const base::StringPiece& data); | 46 void ReceiveData(const base::StringPiece& data); |
48 | 47 |
49 scoped_refptr<net::StreamListenSocket> socket_; | 48 scoped_refptr<StreamListenSocket> socket_; |
50 const HandleRequestCallback callback_; | 49 const HandleRequestCallback callback_; |
51 HttpRequestParser request_parser_; | 50 HttpRequestParser request_parser_; |
52 | 51 |
53 DISALLOW_COPY_AND_ASSIGN(HttpConnection); | 52 DISALLOW_COPY_AND_ASSIGN(HttpConnection); |
54 }; | 53 }; |
55 | 54 |
56 } // namespace test_server | 55 } // namespace test_server |
57 } // namespace google_apis | 56 } // namespace net |
58 | 57 |
59 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_ | 58 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_ |
OLD | NEW |