Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | c700fd15 | 2013-07-23 21:29:11 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_SERVER_HTTP_SERVER_RESPONSE_INFO_H_ |
| 6 | #define NET_SERVER_HTTP_SERVER_RESPONSE_INFO_H_ |
| 7 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
[email protected] | c700fd15 | 2013-07-23 21:29:11 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <utility> |
[email protected] | c700fd15 | 2013-07-23 21:29:11 | [diff] [blame] | 12 | |
payal.pandey | fdae020 | 2015-04-28 06:47:54 | [diff] [blame] | 13 | #include "base/strings/string_split.h" |
[email protected] | c700fd15 | 2013-07-23 21:29:11 | [diff] [blame] | 14 | #include "net/http/http_status_code.h" |
| 15 | |
| 16 | namespace net { |
| 17 | |
| 18 | class HttpServerResponseInfo { |
| 19 | public: |
| 20 | // Creates a 200 OK HttpServerResponseInfo. |
| 21 | HttpServerResponseInfo(); |
| 22 | explicit HttpServerResponseInfo(HttpStatusCode status_code); |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 23 | HttpServerResponseInfo(const HttpServerResponseInfo& other); |
[email protected] | c700fd15 | 2013-07-23 21:29:11 | [diff] [blame] | 24 | ~HttpServerResponseInfo(); |
| 25 | |
| 26 | static HttpServerResponseInfo CreateFor404(); |
| 27 | static HttpServerResponseInfo CreateFor500(const std::string& body); |
| 28 | |
| 29 | void AddHeader(const std::string& name, const std::string& value); |
| 30 | |
| 31 | // This also adds an appropriate Content-Length header. |
| 32 | void SetBody(const std::string& body, const std::string& content_type); |
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame] | 33 | // Sets content-length and content-type. Body should be sent separately. |
| 34 | void SetContentHeaders(size_t content_length, |
| 35 | const std::string& content_type); |
[email protected] | c700fd15 | 2013-07-23 21:29:11 | [diff] [blame] | 36 | |
| 37 | std::string Serialize() const; |
| 38 | |
| 39 | HttpStatusCode status_code() const; |
| 40 | const std::string& body() const; |
| 41 | |
| 42 | private: |
payal.pandey | fdae020 | 2015-04-28 06:47:54 | [diff] [blame] | 43 | using Headers = base::StringPairs; |
[email protected] | c700fd15 | 2013-07-23 21:29:11 | [diff] [blame] | 44 | |
| 45 | HttpStatusCode status_code_; |
| 46 | Headers headers_; |
| 47 | std::string body_; |
| 48 | }; |
| 49 | |
| 50 | } // namespace net |
| 51 | |
| 52 | #endif // NET_SERVER_HTTP_SERVER_RESPONSE_INFO_H_ |