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

Side by Side Diff: net/test/embedded_test_server/default_handlers.cc

Issue 2694923006: [Embedded Test Server] Enable handler HandleEchoHeader echoing multiple headers (Closed)
Patch Set: svaldez comment Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (request_url.has_query()) { 85 std::string vary;
86 std::string header_name = request_url.query(); 86 std::string content;
87 http_response->AddCustomHeader("Vary", header_name); 87 RequestQuery headers = ParseQuery(request_url);
88 for (const auto& header : headers) {
89 std::string header_name = header.first;
90 std::string header_value = "None";
88 if (request.headers.find(header_name) != request.headers.end()) 91 if (request.headers.find(header_name) != request.headers.end())
89 http_response->set_content(request.headers.at(header_name)); 92 header_value = request.headers.at(header_name);
90 else 93 if (!vary.empty())
91 http_response->set_content("None"); 94 vary += ",";
95 vary += header_name;
96 if (!content.empty())
97 content += "\n";
98 content += header_value;
92 } 99 }
93 100
101 http_response->AddCustomHeader("Vary", vary);
102 http_response->set_content(content);
94 http_response->set_content_type("text/plain"); 103 http_response->set_content_type("text/plain");
95 http_response->AddCustomHeader("Cache-Control", cache_control); 104 http_response->AddCustomHeader("Cache-Control", cache_control);
96 return std::move(http_response); 105 return std::move(http_response);
97 } 106 }
98 107
99 // /echo?status=STATUS 108 // /echo?status=STATUS
100 // Responds with the request body as the response body and 109 // Responds with the request body as the response body and
101 // a status code of STATUS. 110 // a status code of STATUS.
102 std::unique_ptr<HttpResponse> HandleEcho(const HttpRequest& request) { 111 std::unique_ptr<HttpResponse> HandleEcho(const HttpRequest& request) {
103 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); 112 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse);
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // TODO(svaldez): HandleGetChannelID 652 // TODO(svaldez): HandleGetChannelID
644 // TODO(svaldez): HandleGetClientCert 653 // TODO(svaldez): HandleGetClientCert
645 // TODO(svaldez): HandleClientCipherList 654 // TODO(svaldez): HandleClientCipherList
646 // TODO(svaldez): HandleEchoMultipartPost 655 // TODO(svaldez): HandleEchoMultipartPost
647 } 656 }
648 657
649 #undef PREFIXED_HANDLER 658 #undef PREFIXED_HANDLER
650 659
651 } // namespace test_server 660 } // namespace test_server
652 } // namespace net 661 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698