cc: Remove PicturePileBase as a base class of PicturePileImpl.
[chromium-blink-merge.git] / net / test / embedded_test_server / http_response.h
blob821c02757dc0e2e1c81475b102d410a4b8f57317
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_RESPONSE_H_
6 #define NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "net/http/http_status_code.h"
16 namespace net {
17 namespace test_server {
19 // Interface for HTTP response implementations.
20 class HttpResponse{
21 public:
22 virtual ~HttpResponse();
24 // Returns raw contents to be written to the network socket
25 // 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.
27 virtual std::string ToResponseString() const = 0;
30 // This class is used to handle basic HTTP responses with commonly used
31 // response headers such as "Content-Type".
32 class BasicHttpResponse : public HttpResponse {
33 public:
34 BasicHttpResponse();
35 ~BasicHttpResponse() override;
37 // The response code.
38 HttpStatusCode code() const { return code_; }
39 void set_code(HttpStatusCode code) { code_ = code; }
41 // The content of the response.
42 const std::string& content() const { return content_; }
43 void set_content(const std::string& content) { content_ = content; }
45 // The content type.
46 const std::string& content_type() const { return content_type_; }
47 void set_content_type(const std::string& content_type) {
48 content_type_ = content_type;
51 // Adds a custom header.
52 void AddCustomHeader(const std::string& key, const std::string& value) {
53 custom_headers_.push_back(std::make_pair(key, value));
56 // Generates and returns a http response string.
57 std::string ToResponseString() const override;
59 private:
60 HttpStatusCode code_;
61 std::string content_;
62 std::string content_type_;
63 std::vector<std::pair<std::string, std::string> > custom_headers_;
65 DISALLOW_COPY_AND_ASSIGN(BasicHttpResponse);
68 } // namespace test_server
69 } // namespace net
71 #endif // NET_TEST_EMBEDDED_TEST_SERVER_HTTP_RESPONSE_H_