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

Side by Side Diff: chrome/browser/google_apis/test_server/http_response.cc

Issue 14971002: GTTF: move chrome/browser/google_apis/test_server to net/test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased, OWNERS Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
(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/google_apis/test_server/http_response.h"
6
7 #include "base/format_macros.h"
8 #include "base/logging.h"
9 #include "base/stringprintf.h"
10
11 namespace google_apis {
12 namespace test_server {
13
14 HttpResponse::HttpResponse() : code_(SUCCESS) {
15 }
16
17 HttpResponse::~HttpResponse() {
18 }
19
20 std::string HttpResponse::ToResponseString() const {
21 // Response line with headers.
22 std::string response_builder;
23
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());
47 }
48 base::StringAppendF(&response_builder, "\r\n");
49
50 return response_builder + content_;
51 }
52
53 } // namespace test_server
54 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698