1 // Copyright 2013 The Chromium Authors 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 8 #include <stddef.h> 9 10 #include <string> 11 #include <utility> 12 13 #include "base/strings/string_split.h" 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); 23 HttpServerResponseInfo(const HttpServerResponseInfo& other); 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); 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); 36 37 std::string Serialize() const; 38 39 HttpStatusCode status_code() const; 40 const std::string& body() const; 41 42 private: 43 using Headers = base::StringPairs; 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_ 53