Fix build break
[chromium-blink-merge.git] / chrome / browser / google_apis / test_server / http_response.cc
blob317f839c9c7f69fb1365ebc67e24ae4b3ca9bde5
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 "chrome/browser/google_apis/test_server/http_response.h"
7 #include "base/format_macros.h"
8 #include "base/logging.h"
9 #include "base/stringprintf.h"
11 namespace google_apis {
12 namespace test_server {
14 HttpResponse::HttpResponse() : code_(SUCCESS) {
17 HttpResponse::~HttpResponse() {
20 std::string HttpResponse::ToResponseString() const {
21 // Response line with headers.
22 std::string response_builder;
24 // TODO(mtomasz): For http/1.0 requests, send http/1.0.
25 // TODO(mtomasz): For different codes, send a corrent string instead of OK.
26 base::StringAppendF(&response_builder, "HTTP/1.1 %d OK\r\n", code_);
27 base::StringAppendF(&response_builder, "Connection: closed\r\n");
28 base::StringAppendF(&response_builder,
29 "Content-Length: %"PRIuS"\r\n",
30 content_.size());
31 base::StringAppendF(&response_builder,
32 "Content-Type: %s\r\n",
33 content_type_.c_str());
34 for (std::map<std::string, std::string>::const_iterator it =
35 custom_headers_.begin();
36 it != custom_headers_.end();
37 ++it) {
38 // Multi-line header value support.
39 const std::string& header_name = it->first;
40 const std::string& header_value = it->second;
41 DCHECK(header_value.find_first_of("\n\r") == std::string::npos) <<
42 "Malformed header value.";
43 base::StringAppendF(&response_builder,
44 "%s: %s\r\n",
45 header_name.c_str(),
46 header_value.c_str());
48 base::StringAppendF(&response_builder, "\r\n");
50 return response_builder + content_;
53 } // namespace test_server
54 } // namespace google_apis