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

Side by Side Diff: net/server/http_server_response_info.cc

Issue 497223003: Revert of Replace StreamListenSocket with StreamSocket in HttpServer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « net/server/http_server_response_info.h ('k') | net/server/http_server_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "net/server/http_server_response_info.h" 5 #include "net/server/http_server_response_info.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "net/http/http_request_headers.h" 9 #include "net/http/http_request_headers.h"
10 10
(...skipping 23 matching lines...) Expand all
34 34
35 void HttpServerResponseInfo::AddHeader(const std::string& name, 35 void HttpServerResponseInfo::AddHeader(const std::string& name,
36 const std::string& value) { 36 const std::string& value) {
37 headers_.push_back(std::make_pair(name, value)); 37 headers_.push_back(std::make_pair(name, value));
38 } 38 }
39 39
40 void HttpServerResponseInfo::SetBody(const std::string& body, 40 void HttpServerResponseInfo::SetBody(const std::string& body,
41 const std::string& content_type) { 41 const std::string& content_type) {
42 DCHECK(body_.empty()); 42 DCHECK(body_.empty());
43 body_ = body; 43 body_ = body;
44 SetContentHeaders(body.length(), content_type);
45 }
46
47 void HttpServerResponseInfo::SetContentHeaders(
48 size_t content_length,
49 const std::string& content_type) {
50 AddHeader(HttpRequestHeaders::kContentLength, 44 AddHeader(HttpRequestHeaders::kContentLength,
51 base::StringPrintf("%" PRIuS, content_length)); 45 base::StringPrintf("%" PRIuS, body.length()));
52 AddHeader(HttpRequestHeaders::kContentType, content_type); 46 AddHeader(HttpRequestHeaders::kContentType, content_type);
53 } 47 }
54 48
55 std::string HttpServerResponseInfo::Serialize() const { 49 std::string HttpServerResponseInfo::Serialize() const {
56 std::string response = base::StringPrintf( 50 std::string response = base::StringPrintf(
57 "HTTP/1.1 %d %s\r\n", status_code_, GetHttpReasonPhrase(status_code_)); 51 "HTTP/1.1 %d %s\r\n", status_code_, GetHttpReasonPhrase(status_code_));
58 Headers::const_iterator header; 52 Headers::const_iterator header;
59 for (header = headers_.begin(); header != headers_.end(); ++header) 53 for (header = headers_.begin(); header != headers_.end(); ++header)
60 response += header->first + ":" + header->second + "\r\n"; 54 response += header->first + ":" + header->second + "\r\n";
61 55
62 return response + "\r\n" + body_; 56 return response + "\r\n" + body_;
63 } 57 }
64 58
65 HttpStatusCode HttpServerResponseInfo::status_code() const { 59 HttpStatusCode HttpServerResponseInfo::status_code() const {
66 return status_code_; 60 return status_code_;
67 } 61 }
68 62
69 const std::string& HttpServerResponseInfo::body() const { 63 const std::string& HttpServerResponseInfo::body() const {
70 return body_; 64 return body_;
71 } 65 }
72 66
73 } // namespace net 67 } // namespace net
OLDNEW
« no previous file with comments | « net/server/http_server_response_info.h ('k') | net/server/http_server_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698