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

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: More cleanup. 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> 8 #include <map>
mmenke 2015/10/14 21:59:16 While you're here, I don't think this is needed (T
svaldez 2015/10/14 22:33:40 Done.
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
14 #include "net/http/http_status_code.h" 15 #include "net/http/http_status_code.h"
15 16
16 namespace net { 17 namespace net {
17 namespace test_server { 18 namespace test_server {
18 19
20 // Callback called when the response is done being sent.
21 using SendDoneCallback = base::Callback<void(void)>;
mmenke 2015/10/14 21:59:16 Suggest Done->Complete (Complete's a bit more comm
svaldez 2015/10/14 22:33:40 Done.
22
23 // Callback called when the response is ready to be sent.
mmenke 2015/10/14 21:59:16 Document done.
svaldez 2015/10/14 22:33:40 Done.
24 using SendCallback =
25 base::Callback<void(std::string response, SendDoneCallback done)>;
mmenke 2015/10/14 21:59:16 Suggest calling this SendBytesCallback to more cle
svaldez 2015/10/14 22:33:40 Done.
26
19 // Interface for HTTP response implementations. 27 // Interface for HTTP response implementations.
20 class HttpResponse{ 28 class HttpResponse{
21 public: 29 public:
22 virtual ~HttpResponse(); 30 virtual ~HttpResponse();
23 31
24 // Returns raw contents to be written to the network socket 32 // Calls |send| with the raw contents to be written to the network socket
25 // in response. If you intend to make this a valid HTTP response, 33 // in response. If you intend to make this a valid HTTP response,
26 // it should start with "HTTP/x.x" line, followed by response headers. 34 // it should start with "HTTP/x.x" line, followed by response headers.
27 virtual std::string ToResponseString() const = 0; 35 // May call |send| reentrantly. If the HttpResponse is destroyed before
36 // the operation completes, the callback will not be called.
mmenke 2015/10/14 21:59:16 Think this documentation should be targeted at imp
svaldez 2015/10/14 22:33:40 Done.
37 virtual void SendResponse(SendCallback send, SendDoneCallback done) = 0;
mmenke 2015/10/14 21:59:16 I assume you can use SendCallback and your own sen
svaldez 2015/10/14 22:33:40 Done.
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".
mmenke 2015/10/14 21:59:16 Maybe add something along the lines of "Sends the
svaldez 2015/10/14 22:33:40 Done.
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(SendCallback send, SendDoneCallback done) override;
58 70
59 private: 71 private:
60 HttpStatusCode code_; 72 HttpStatusCode code_;
61 std::string content_; 73 std::string content_;
62 std::string content_type_; 74 std::string content_type_;
63 base::StringPairs custom_headers_; 75 base::StringPairs custom_headers_;
64 76
65 DISALLOW_COPY_AND_ASSIGN(BasicHttpResponse); 77 DISALLOW_COPY_AND_ASSIGN(BasicHttpResponse);
66 }; 78 };
67 79
68 } // namespace test_server 80 } // namespace test_server
69 } // namespace net 81 } // namespace net
70 82
71 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_ 83 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698