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/google_apis/test_server/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_server { | |
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, "Connection: closed\r\n"); | |
30 base::StringAppendF(&response_builder, | |
31 "Content-Length: %zu\r\n", | |
32 content.length()); | |
33 base::StringAppendF(&response_builder, | |
34 "Content-Type: %s\r\n", | |
35 content_type.c_str()); | |
36 for (std::map<std::string, std::string>::const_iterator it = | |
37 custom_headers.begin(); | |
38 it != custom_headers.end(); | |
39 it++) { | |
Lei Zhang
2012/11/14 05:05:43
nit: ++it
satorux1
2012/11/14 05:13:39
Done.
| |
40 // Multi-line header value support. | |
41 const std::string& header_name = it->first.c_str(); | |
42 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.
| |
43 DCHECK(header_value.find_first_of("\n\r") == std::string::npos) << | |
44 "Malformed header value."; | |
45 base::StringAppendF(&response_builder, | |
46 "%s: %s\r\n", | |
47 header_name.c_str(), | |
48 header_value.c_str()); | |
49 } | |
50 base::StringAppendF(&response_builder, "\r\n"); | |
51 | |
52 // Append content data. | |
53 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.
| |
54 | |
55 return response_builder; | |
56 } | |
57 | |
58 } // namespace test_server | |
59 } // namespace drive | |
OLD | NEW |