Remove unused var from OffTheRecordProfileImplTest.GetHostZoomMap
[chromium-blink-merge.git] / net / test / embedded_test_server / http_response.cc
blob04155b5ffa529781480646dfa57f8a39caea081b
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
3 // found in the LICENSE file.
5 #include "net/test/embedded_test_server/http_response.h"
7 #include "base/format_macros.h"
8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h"
10 #include "net/http/http_status_code.h"
12 namespace net {
13 namespace test_server {
15 HttpResponse::~HttpResponse() {
18 BasicHttpResponse::BasicHttpResponse() : code_(HTTP_OK) {
21 BasicHttpResponse::~BasicHttpResponse() {
24 std::string BasicHttpResponse::ToResponseString() const {
25 // Response line with headers.
26 std::string response_builder;
28 std::string http_reason_phrase(GetHttpReasonPhrase(code_));
30 // TODO(mtomasz): For http/1.0 requests, send http/1.0.
31 base::StringAppendF(&response_builder,
32 "HTTP/1.1 %d %s\r\n",
33 code_,
34 http_reason_phrase.c_str());
35 base::StringAppendF(&response_builder, "Connection: close\r\n");
36 base::StringAppendF(&response_builder,
37 "Content-Length: %" PRIuS "\r\n",
38 content_.size());
39 base::StringAppendF(&response_builder,
40 "Content-Type: %s\r\n",
41 content_type_.c_str());
42 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_value = custom_headers_[i].second;
45 DCHECK(header_value.find_first_of("\n\r") == std::string::npos) <<
46 "Malformed header value.";
47 base::StringAppendF(&response_builder,
48 "%s: %s\r\n",
49 header_name.c_str(),
50 header_value.c_str());
52 base::StringAppendF(&response_builder, "\r\n");
54 return response_builder + content_;
57 } // namespace test_server
58 } // namespace net