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_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> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 namespace test_server { | 15 namespace test_server { |
15 | 16 |
16 enum ResponseCode { | 17 enum ResponseCode { |
17 SUCCESS = 200, | 18 SUCCESS = 200, |
18 CREATED = 201, | 19 CREATED = 201, |
19 NO_CONTENT = 204, | 20 NO_CONTENT = 204, |
20 MOVED = 301, | 21 MOVED = 301, |
21 RESUME_INCOMPLETE = 308, | 22 RESUME_INCOMPLETE = 308, |
22 NOT_FOUND = 404, | 23 NOT_FOUND = 404, |
23 PRECONDITION = 412, | 24 PRECONDITION = 412, |
24 ACCESS_DENIED = 500, | 25 ACCESS_DENIED = 500, |
25 }; | 26 }; |
26 | 27 |
27 // Respresents a HTTP response. Since it can be big, it may be better to use | 28 // Respresents a HTTP response. |
Avi (use Gerrit)
2013/05/21 00:24:22
fix typo
Paweł Hajdan Jr.
2013/05/21 17:56:03
Done.
| |
28 // scoped_ptr to pass it instead of copying. | |
29 class HttpResponse { | 29 class HttpResponse { |
30 public: | 30 public: |
31 HttpResponse(); | 31 virtual ~HttpResponse(); |
32 ~HttpResponse(); | 32 |
33 virtual std::string ToResponseString() const = 0; | |
satorux1
2013/05/21 07:40:18
function comment is missing. maybe:
// Returns a
Paweł Hajdan Jr.
2013/05/21 17:56:03
Updated. Note that one of the implementations deli
| |
34 }; | |
35 | |
36 class HttpResponseImpl : public HttpResponse { | |
satorux1
2013/05/21 07:40:18
I found this name unusual. Usually classes named "
Paweł Hajdan Jr.
2013/05/21 17:56:03
Done.
| |
37 public: | |
38 HttpResponseImpl(); | |
39 ~HttpResponseImpl(); | |
33 | 40 |
34 // The response code. | 41 // The response code. |
35 ResponseCode code() const { return code_; } | 42 ResponseCode code() const { return code_; } |
36 void set_code(ResponseCode code) { code_ = code; } | 43 void set_code(ResponseCode code) { code_ = code; } |
37 | 44 |
38 // The content of the response. | 45 // The content of the response. |
39 const std::string& content() const { return content_; } | 46 const std::string& content() const { return content_; } |
40 void set_content(const std::string& content) { content_ = content; } | 47 void set_content(const std::string& content) { content_ = content; } |
41 | 48 |
42 // The content type. | 49 // The content type. |
43 const std::string& content_type() const { return content_type_; } | 50 const std::string& content_type() const { return content_type_; } |
44 void set_content_type(const std::string& content_type) { | 51 void set_content_type(const std::string& content_type) { |
45 content_type_ = content_type; | 52 content_type_ = content_type; |
46 } | 53 } |
47 | 54 |
48 // The custom headers to be sent to the client. | 55 // The custom headers to be sent to the client. |
49 const std::map<std::string, std::string>& custom_headers() const { | 56 const std::map<std::string, std::string>& custom_headers() const { |
50 return custom_headers_; | 57 return custom_headers_; |
51 } | 58 } |
52 | 59 |
53 // Adds a custom header. | 60 // Adds a custom header. |
54 void AddCustomHeader(const std::string& key, const std::string& value) { | 61 void AddCustomHeader(const std::string& key, const std::string& value) { |
55 custom_headers_[key] = value; | 62 custom_headers_[key] = value; |
56 } | 63 } |
57 | 64 |
58 // Generates and returns a http response string. | 65 // Generates and returns a http response string. |
59 std::string ToResponseString() const; | 66 virtual std::string ToResponseString() const OVERRIDE; |
60 | 67 |
61 private: | 68 private: |
62 ResponseCode code_; | 69 ResponseCode code_; |
63 std::string content_; | 70 std::string content_; |
64 std::string content_type_; | 71 std::string content_type_; |
65 std::map<std::string, std::string> custom_headers_; | 72 std::map<std::string, std::string> custom_headers_; |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(HttpResponseImpl); | |
66 }; | 75 }; |
67 | 76 |
68 } // namespace test_server | 77 } // namespace test_server |
69 } // namespace net | 78 } // namespace net |
70 | 79 |
71 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_ | 80 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_ |
OLD | NEW |