Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: net/test/embedded_test_server/http_response.h

Issue 1376593007: SSL in EmbeddedTestServer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding TODO to fix handlers post-Start. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_RESPONSE_H_ 5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_
6 #define NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_ 6 #define NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_
7 7
8 #include <map>
9 #include <string> 8 #include <string>
10 9
11 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "net/http/http_status_code.h" 14 #include "net/http/http_status_code.h"
15 15
16 namespace net { 16 namespace net {
17 namespace test_server { 17 namespace test_server {
18 18
19 // Callback called when the response is done being sent.
20 using SendCompleteCallback = base::Callback<void(void)>;
21
22 // Callback called when the response is ready to be sent that takes the
23 // |response| that is being sent along with the callback |write_done| that is
24 // called when the response has been fully written.
25 using SendBytesCallback = base::Callback<void(const std::string& response,
26 SendCompleteCallback write_done)>;
mmenke 2015/10/21 20:30:39 nit: const SendCompleteCallback&
svaldez 2015/10/21 21:22:29 Done.
27
19 // Interface for HTTP response implementations. 28 // Interface for HTTP response implementations.
20 class HttpResponse{ 29 class HttpResponse{
21 public: 30 public:
22 virtual ~HttpResponse(); 31 virtual ~HttpResponse();
23 32
24 // Returns raw contents to be written to the network socket 33 // |send| will send the specified data to the network socket, and invoke
25 // in response. If you intend to make this a valid HTTP response, 34 // |write_done| when complete. When the entire response has been sent,
26 // it should start with "HTTP/x.x" line, followed by response headers. 35 // |done| must be called.
27 virtual std::string ToResponseString() const = 0; 36 virtual void SendResponse(const SendBytesCallback& send,
37 const SendCompleteCallback& done) = 0;
28 }; 38 };
29 39
30 // This class is used to handle basic HTTP responses with commonly used 40 // This class is used to handle basic HTTP responses with commonly used
31 // response headers such as "Content-Type". 41 // response headers such as "Content-Type". Sends the response immediately.
32 class BasicHttpResponse : public HttpResponse { 42 class BasicHttpResponse : public HttpResponse {
33 public: 43 public:
34 BasicHttpResponse(); 44 BasicHttpResponse();
35 ~BasicHttpResponse() override; 45 ~BasicHttpResponse() override;
36 46
37 // The response code. 47 // The response code.
38 HttpStatusCode code() const { return code_; } 48 HttpStatusCode code() const { return code_; }
39 void set_code(HttpStatusCode code) { code_ = code; } 49 void set_code(HttpStatusCode code) { code_ = code; }
40 50
41 // The content of the response. 51 // The content of the response.
42 const std::string& content() const { return content_; } 52 const std::string& content() const { return content_; }
43 void set_content(const std::string& content) { content_ = content; } 53 void set_content(const std::string& content) { content_ = content; }
44 54
45 // The content type. 55 // The content type.
46 const std::string& content_type() const { return content_type_; } 56 const std::string& content_type() const { return content_type_; }
47 void set_content_type(const std::string& content_type) { 57 void set_content_type(const std::string& content_type) {
48 content_type_ = content_type; 58 content_type_ = content_type;
49 } 59 }
50 60
51 // Adds a custom header. 61 // Adds a custom header.
52 void AddCustomHeader(const std::string& key, const std::string& value) { 62 void AddCustomHeader(const std::string& key, const std::string& value) {
53 custom_headers_.push_back(std::make_pair(key, value)); 63 custom_headers_.push_back(std::make_pair(key, value));
54 } 64 }
55 65
56 // Generates and returns a http response string. 66 // Generates and returns a http response string.
57 std::string ToResponseString() const override; 67 std::string ToResponseString() const;
68
69 void SendResponse(const SendBytesCallback& send,
70 const SendCompleteCallback& done) override;
58 71
59 private: 72 private:
60 HttpStatusCode code_; 73 HttpStatusCode code_;
61 std::string content_; 74 std::string content_;
62 std::string content_type_; 75 std::string content_type_;
63 base::StringPairs custom_headers_; 76 base::StringPairs custom_headers_;
64 77
65 DISALLOW_COPY_AND_ASSIGN(BasicHttpResponse); 78 DISALLOW_COPY_AND_ASSIGN(BasicHttpResponse);
66 }; 79 };
67 80
68 } // namespace test_server 81 } // namespace test_server
69 } // namespace net 82 } // namespace net
70 83
71 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_ 84 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698