Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/test/embedded_test_server/default_handlers.h" | 5 #include "net/test/embedded_test_server/default_handlers.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <ctime> | 8 #include <ctime> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 // Returns a cacheable response. | 63 // Returns a cacheable response. |
| 64 std::unique_ptr<HttpResponse> HandleCacheTime(const HttpRequest& request) { | 64 std::unique_ptr<HttpResponse> HandleCacheTime(const HttpRequest& request) { |
| 65 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | 65 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); |
| 66 http_response->set_content( | 66 http_response->set_content( |
| 67 "<html><head><title>Cache: max-age=60</title></head></html>"); | 67 "<html><head><title>Cache: max-age=60</title></head></html>"); |
| 68 http_response->set_content_type("text/html"); | 68 http_response->set_content_type("text/html"); |
| 69 http_response->AddCustomHeader("Cache-Control", "max-age=60"); | 69 http_response->AddCustomHeader("Cache-Control", "max-age=60"); |
| 70 return std::move(http_response); | 70 return std::move(http_response); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // /echoheader | /echoheadercache | 73 // /echoheader?HEADERS | /echoheadercache?HEADERS |
| 74 // Responds with the headers echoed in the message body. | 74 // Responds with the headers echoed in the message body. |
| 75 // echoheader does not cache the results, while echoheadercache does. | 75 // echoheader does not cache the results, while echoheadercache does. |
| 76 std::unique_ptr<HttpResponse> HandleEchoHeader(const std::string& url, | 76 std::unique_ptr<HttpResponse> HandleEchoHeader(const std::string& url, |
| 77 const std::string& cache_control, | 77 const std::string& cache_control, |
| 78 const HttpRequest& request) { | 78 const HttpRequest& request) { |
| 79 if (!ShouldHandle(request, url)) | 79 if (!ShouldHandle(request, url)) |
| 80 return nullptr; | 80 return nullptr; |
| 81 | 81 |
| 82 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | 82 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); |
| 83 | 83 |
| 84 GURL request_url = request.GetURL(); | 84 GURL request_url = request.GetURL(); |
| 85 std::string content; | |
| 85 if (request_url.has_query()) { | 86 if (request_url.has_query()) { |
| 86 std::string header_name = request_url.query(); | 87 std::vector<std::string> header_names = base::SplitString( |
|
svaldez
2017/02/14 20:23:43
std::string vary;
std::string content;
RequestQuer
shenghuazhang
2017/02/15 01:14:03
Done.
| |
| 87 http_response->AddCustomHeader("Vary", header_name); | 88 request_url.query(), "&", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 88 if (request.headers.find(header_name) != request.headers.end()) | 89 for (const auto& header_name : header_names) { |
| 89 http_response->set_content(request.headers.at(header_name)); | 90 http_response->AddCustomHeader("Vary", header_name); |
| 90 else | 91 if (!content.empty()) |
| 91 http_response->set_content("None"); | 92 content += "\n"; |
|
shenghuazhang
2017/02/14 20:06:42
I used "\n" to separate the header values here. Bu
| |
| 93 if (request.headers.find(header_name) != request.headers.end()) | |
| 94 content += request.headers.at(header_name); | |
| 95 else | |
| 96 content += "None"; | |
| 97 } | |
| 92 } | 98 } |
| 93 | 99 |
| 100 http_response->set_content(content); | |
| 94 http_response->set_content_type("text/plain"); | 101 http_response->set_content_type("text/plain"); |
| 95 http_response->AddCustomHeader("Cache-Control", cache_control); | 102 http_response->AddCustomHeader("Cache-Control", cache_control); |
| 96 return std::move(http_response); | 103 return std::move(http_response); |
| 97 } | 104 } |
| 98 | 105 |
| 99 // /echo?status=STATUS | 106 // /echo?status=STATUS |
| 100 // Responds with the request body as the response body and | 107 // Responds with the request body as the response body and |
| 101 // a status code of STATUS. | 108 // a status code of STATUS. |
| 102 std::unique_ptr<HttpResponse> HandleEcho(const HttpRequest& request) { | 109 std::unique_ptr<HttpResponse> HandleEcho(const HttpRequest& request) { |
| 103 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | 110 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 // TODO(svaldez): HandleGetChannelID | 650 // TODO(svaldez): HandleGetChannelID |
| 644 // TODO(svaldez): HandleGetClientCert | 651 // TODO(svaldez): HandleGetClientCert |
| 645 // TODO(svaldez): HandleClientCipherList | 652 // TODO(svaldez): HandleClientCipherList |
| 646 // TODO(svaldez): HandleEchoMultipartPost | 653 // TODO(svaldez): HandleEchoMultipartPost |
| 647 } | 654 } |
| 648 | 655 |
| 649 #undef PREFIXED_HANDLER | 656 #undef PREFIXED_HANDLER |
| 650 | 657 |
| 651 } // namespace test_server | 658 } // namespace test_server |
| 652 } // namespace net | 659 } // namespace net |
| OLD | NEW |