blob: d20b7496762ab45ce952db338e916df0dce3b4a8 [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2013 The Chromium Authors
[email protected]c700fd152013-07-23 21:29:112// 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 Drissman13fc8932015-12-20 04:40:468#include <stddef.h>
9
[email protected]c700fd152013-07-23 21:29:1110#include <string>
11#include <utility>
[email protected]c700fd152013-07-23 21:29:1112
payal.pandeyfdae0202015-04-28 06:47:5413#include "base/strings/string_split.h"
[email protected]c700fd152013-07-23 21:29:1114#include "net/http/http_status_code.h"
15
16namespace net {
17
18class HttpServerResponseInfo {
19 public:
20 // Creates a 200 OK HttpServerResponseInfo.
21 HttpServerResponseInfo();
22 explicit HttpServerResponseInfo(HttpStatusCode status_code);
vmpstracd23b72016-02-26 21:08:5523 HttpServerResponseInfo(const HttpServerResponseInfo& other);
[email protected]c700fd152013-07-23 21:29:1124 ~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);
byungchul38c3ae72014-08-25 23:27:4633 // 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]c700fd152013-07-23 21:29:1136
37 std::string Serialize() const;
38
39 HttpStatusCode status_code() const;
40 const std::string& body() const;
41
42 private:
payal.pandeyfdae0202015-04-28 06:47:5443 using Headers = base::StringPairs;
[email protected]c700fd152013-07-23 21:29:1144
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_