OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/drive/test_servers/http_response.h" |
| 6 |
| 7 #include <map> |
| 8 #include <string> |
| 9 |
| 10 #include "base/string_util.h" |
| 11 #include "base/stringprintf.h" |
| 12 |
| 13 namespace drive { |
| 14 namespace test_servers { |
| 15 |
| 16 HttpResponse::HttpResponse() : code(SUCCESS) { |
| 17 } |
| 18 |
| 19 HttpResponse::~HttpResponse() { |
| 20 } |
| 21 |
| 22 std::string HttpResponse::ToResponseString() const { |
| 23 // Response line with headers. |
| 24 std::string response_builder; |
| 25 |
| 26 // TODO(mtomasz): For http/1.0 requests, send http/1.0. |
| 27 // TODO(mtomasz): For different codes, send a corrent string instead of OK. |
| 28 base::StringAppendF(&response_builder, "HTTP/1.1 %d OK\r\n", code); |
| 29 base::StringAppendF(&response_builder, |
| 30 "Content-Length: %zu\r\n", |
| 31 content.length()); |
| 32 base::StringAppendF(&response_builder, |
| 33 "Content-Type: %s\r\n", |
| 34 content_type.c_str()); |
| 35 for (std::map<std::string, std::string>::const_iterator it = |
| 36 custom_headers.begin(); |
| 37 it != custom_headers.end(); |
| 38 it++) { |
| 39 // Multi-line header value support. |
| 40 const std::string& header_name = it->first.c_str(); |
| 41 std::string header_value = it->second.c_str(); |
| 42 ReplaceSubstringsAfterOffset(&header_value, 0, "\n", "\r\n "); |
| 43 base::StringAppendF(&response_builder, |
| 44 "%s: %s\r\n", |
| 45 header_name.c_str(), |
| 46 header_value.c_str()); |
| 47 } |
| 48 base::StringAppendF(&response_builder, "\r\n"); |
| 49 |
| 50 // Append content data. |
| 51 response_builder += content; |
| 52 |
| 53 return response_builder; |
| 54 } |
| 55 |
| 56 } // namespace test_servers |
| 57 } // namespace drive |
OLD | NEW |