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
3 // found in the LICENSE file.
5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_
6 #define NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/strings/string_piece.h"
11 #include "net/test/embedded_test_server/http_request.h"
15 namespace test_server
{
19 class StreamListenSocket
;
21 // Calblack called when a request is parsed. Response should be sent
22 // using HttpConnection::SendResponse() on the |connection| argument.
23 typedef base::Callback
<void(HttpConnection
* connection
,
24 scoped_ptr
<HttpRequest
> request
)>
25 HandleRequestCallback
;
27 // Wraps the connection socket. Accepts incoming data and sends responses.
28 // If a valid request is parsed, then |callback_| is invoked.
29 class HttpConnection
{
31 HttpConnection(scoped_ptr
<StreamListenSocket
> socket
,
32 const HandleRequestCallback
& callback
);
35 // Sends the HTTP response to the client.
36 void SendResponse(scoped_ptr
<HttpResponse
> response
) const;
39 friend class EmbeddedTestServer
;
41 // Accepts raw chunk of data from the client. Internally, passes it to the
42 // HttpRequestParser class. If a request is parsed, then |callback_| is
44 void ReceiveData(const base::StringPiece
& data
);
46 scoped_ptr
<StreamListenSocket
> socket_
;
47 const HandleRequestCallback callback_
;
48 HttpRequestParser request_parser_
;
50 DISALLOW_COPY_AND_ASSIGN(HttpConnection
);
53 } // namespace test_server
56 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_CONNECTION_H_