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

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

Issue 15505003: GTTF: Convert most tests in content to use EmbeddedTestServer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 7 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 | Annotate | Revision Log
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>
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 // Interface for HTTP response implementations.
28 // scoped_ptr to pass it instead of copying. 29 class HttpResponseInterface {
29 class HttpResponse { 30 public:
31 virtual ~HttpResponseInterface();
32
33 // Returns raw contents to be written to the network socket
34 // in response. If you intend to make this a valid HTTP response,
35 // it should start with "HTTP/x.x" line, followed by response headers.
36 virtual std::string ToResponseString() const = 0;
37 };
38
39 // This class is used to handle basic HTTP responses with commonly used
40 // response headers such as "Content-Type".
41 class HttpResponse : public HttpResponseInterface {
satorux1 2013/05/22 01:54:56 I suggested this name, but I changed my mind (sorr
Paweł Hajdan Jr. 2013/05/22 21:01:38 Done.
30 public: 42 public:
31 HttpResponse(); 43 HttpResponse();
32 ~HttpResponse(); 44 ~HttpResponse();
33 45
34 // The response code. 46 // The response code.
35 ResponseCode code() const { return code_; } 47 ResponseCode code() const { return code_; }
36 void set_code(ResponseCode code) { code_ = code; } 48 void set_code(ResponseCode code) { code_ = code; }
37 49
38 // The content of the response. 50 // The content of the response.
39 const std::string& content() const { return content_; } 51 const std::string& content() const { return content_; }
40 void set_content(const std::string& content) { content_ = content; } 52 void set_content(const std::string& content) { content_ = content; }
41 53
42 // The content type. 54 // The content type.
43 const std::string& content_type() const { return content_type_; } 55 const std::string& content_type() const { return content_type_; }
44 void set_content_type(const std::string& content_type) { 56 void set_content_type(const std::string& content_type) {
45 content_type_ = content_type; 57 content_type_ = content_type;
46 } 58 }
47 59
48 // The custom headers to be sent to the client. 60 // The custom headers to be sent to the client.
49 const std::map<std::string, std::string>& custom_headers() const { 61 const std::map<std::string, std::string>& custom_headers() const {
50 return custom_headers_; 62 return custom_headers_;
51 } 63 }
52 64
53 // Adds a custom header. 65 // Adds a custom header.
54 void AddCustomHeader(const std::string& key, const std::string& value) { 66 void AddCustomHeader(const std::string& key, const std::string& value) {
55 custom_headers_[key] = value; 67 custom_headers_[key] = value;
56 } 68 }
57 69
58 // Generates and returns a http response string. 70 // Generates and returns a http response string.
59 std::string ToResponseString() const; 71 virtual std::string ToResponseString() const OVERRIDE;
60 72
61 private: 73 private:
62 ResponseCode code_; 74 ResponseCode code_;
63 std::string content_; 75 std::string content_;
64 std::string content_type_; 76 std::string content_type_;
65 std::map<std::string, std::string> custom_headers_; 77 std::map<std::string, std::string> custom_headers_;
78
79 DISALLOW_COPY_AND_ASSIGN(HttpResponse);
66 }; 80 };
67 81
68 } // namespace test_server 82 } // namespace test_server
69 } // namespace net 83 } // namespace net
70 84
71 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_ 85 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698