Chromium Code Reviews| Index: chrome/browser/google_apis/test_server/http_response.cc |
| diff --git a/chrome/browser/google_apis/test_server/http_response.cc b/chrome/browser/google_apis/test_server/http_response.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1cf9dcf3abf3e629486578c2058aac10611dee8d |
| --- /dev/null |
| +++ b/chrome/browser/google_apis/test_server/http_response.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/google_apis/test_server/http_response.h" |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/string_util.h" |
| +#include "base/stringprintf.h" |
| + |
| +namespace drive { |
| +namespace test_server { |
| + |
| +HttpResponse::HttpResponse() : code(SUCCESS) { |
| +} |
| + |
| +HttpResponse::~HttpResponse() { |
| +} |
| + |
| +std::string HttpResponse::ToResponseString() const { |
| + // Response line with headers. |
| + std::string response_builder; |
| + |
| + // TODO(mtomasz): For http/1.0 requests, send http/1.0. |
| + // TODO(mtomasz): For different codes, send a corrent string instead of OK. |
| + base::StringAppendF(&response_builder, "HTTP/1.1 %d OK\r\n", code); |
| + base::StringAppendF(&response_builder, "Connection: closed\r\n"); |
| + base::StringAppendF(&response_builder, |
| + "Content-Length: %zu\r\n", |
| + content.length()); |
| + base::StringAppendF(&response_builder, |
| + "Content-Type: %s\r\n", |
| + content_type.c_str()); |
| + for (std::map<std::string, std::string>::const_iterator it = |
| + custom_headers.begin(); |
| + it != custom_headers.end(); |
| + it++) { |
|
Lei Zhang
2012/11/14 05:05:43
nit: ++it
satorux1
2012/11/14 05:13:39
Done.
|
| + // Multi-line header value support. |
| + const std::string& header_name = it->first.c_str(); |
| + std::string header_value = it->second.c_str(); |
|
Lei Zhang
2012/11/14 05:05:43
why can't this be const ref as well?
satorux1
2012/11/14 05:13:39
Done. Removed c_str() from the two lines too.
|
| + DCHECK(header_value.find_first_of("\n\r") == std::string::npos) << |
| + "Malformed header value."; |
| + base::StringAppendF(&response_builder, |
| + "%s: %s\r\n", |
| + header_name.c_str(), |
| + header_value.c_str()); |
| + } |
| + base::StringAppendF(&response_builder, "\r\n"); |
| + |
| + // Append content data. |
| + response_builder += content; |
|
Lei Zhang
2012/11/14 05:05:43
just write: return response_builder + content
satorux1
2012/11/14 05:13:39
Done.
|
| + |
| + return response_builder; |
| +} |
| + |
| +} // namespace test_server |
| +} // namespace drive |