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

Side by Side Diff: net/test/embedded_test_server/http_response.cc

Issue 1376593007: SSL in EmbeddedTestServer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing unused macros. Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/test/embedded_test_server/http_response.h" 5 #include "net/test/embedded_test_server/http_response.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "net/http/http_status_code.h" 10 #include "net/http/http_status_code.h"
(...skipping 15 matching lines...) Expand all
26 std::string response_builder; 26 std::string response_builder;
27 27
28 std::string http_reason_phrase(GetHttpReasonPhrase(code_)); 28 std::string http_reason_phrase(GetHttpReasonPhrase(code_));
29 29
30 // TODO(mtomasz): For http/1.0 requests, send http/1.0. 30 // TODO(mtomasz): For http/1.0 requests, send http/1.0.
31 base::StringAppendF(&response_builder, 31 base::StringAppendF(&response_builder,
32 "HTTP/1.1 %d %s\r\n", 32 "HTTP/1.1 %d %s\r\n",
33 code_, 33 code_,
34 http_reason_phrase.c_str()); 34 http_reason_phrase.c_str());
35 base::StringAppendF(&response_builder, "Connection: close\r\n"); 35 base::StringAppendF(&response_builder, "Connection: close\r\n");
36 base::StringAppendF(&response_builder, 36
37 "Content-Length: %" PRIuS "\r\n", 37 if (content_type_.size() != 0 || content_.size() != 0) {
38 content_.size()); 38 base::StringAppendF(&response_builder, "Content-Length: %" PRIuS "\r\n",
39 base::StringAppendF(&response_builder, 39 content_.size());
mmenke 2015/10/19 18:07:41 Why don't we send a content-length when when the c
svaldez 2015/10/19 21:56:15 For responses that are only sending headers back,
mmenke 2015/10/21 18:45:22 I'm not following. Our network stack handles Cont
40 "Content-Type: %s\r\n", 40 base::StringAppendF(&response_builder, "Content-Type: %s\r\n",
41 content_type_.c_str()); 41 content_type_.c_str());
42 }
42 for (size_t i = 0; i < custom_headers_.size(); ++i) { 43 for (size_t i = 0; i < custom_headers_.size(); ++i) {
43 const std::string& header_name = custom_headers_[i].first; 44 const std::string& header_name = custom_headers_[i].first;
44 const std::string& header_value = custom_headers_[i].second; 45 const std::string& header_value = custom_headers_[i].second;
45 DCHECK(header_value.find_first_of("\n\r") == std::string::npos) << 46 DCHECK(header_value.find_first_of("\n\r") == std::string::npos) <<
46 "Malformed header value."; 47 "Malformed header value.";
47 base::StringAppendF(&response_builder, 48 base::StringAppendF(&response_builder,
48 "%s: %s\r\n", 49 "%s: %s\r\n",
49 header_name.c_str(), 50 header_name.c_str(),
50 header_value.c_str()); 51 header_value.c_str());
51 } 52 }
52 base::StringAppendF(&response_builder, "\r\n"); 53 base::StringAppendF(&response_builder, "\r\n");
53 54
54 return response_builder + content_; 55 return response_builder + content_;
55 } 56 }
56 57
58 void BasicHttpResponse::SendResponse(SendBytesCallback send,
59 SendCompleteCallback done) {
60 send.Run(ToResponseString(), done);
61 }
62
57 } // namespace test_server 63 } // namespace test_server
58 } // namespace net 64 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698