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

Unified Diff: net/test/embedded_test_server/request_helpers.h

Issue 1376593007: SSL in EmbeddedTestServer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaning up request handler. Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: net/test/embedded_test_server/request_helpers.h
diff --git a/net/test/embedded_test_server/request_helpers.h b/net/test/embedded_test_server/request_helpers.h
new file mode 100644
index 0000000000000000000000000000000000000000..4bdaaebac9c145ce689d87fceb82f080f33afec4
--- /dev/null
+++ b/net/test/embedded_test_server/request_helpers.h
@@ -0,0 +1,63 @@
+// Copyright 2015 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.
+
+#ifndef NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HELPERS_H_
+#define NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HELPERS_H_
+
+#include <utility>
+
+#include "base/files/file_path.h"
+#include "base/strings/string_split.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/embedded_test_server/http_request.h"
+#include "net/test/embedded_test_server/http_response.h"
+#include "url/gurl.h"
+
+namespace net {
+namespace test_server {
+
+// This file is only meant for compatibility with testserver.py. No
+// additional handlers should be added here that don't affect multiple
+// distinct tests.
+
+using RequestQuery = std::map<std::string, std::vector<std::string>>;
+
+class CustomHttpResponse : public HttpResponse {
+ public:
+ CustomHttpResponse(const std::string& headers, const std::string& contents)
+ : headers_(headers), contents_(contents) {}
+
+ void SendResponse(SendBytesCallback send, SendCompleteCallback done) override;
+
+ private:
+ std::string headers_;
+ std::string contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(CustomHttpResponse);
+};
+
+// Return whether |request| starts with a URL path of |url|.
+bool ShouldHandle(const HttpRequest& request, std::string url);
+
+// Parses |data| as the query of a URL and places it into a map.
+RequestQuery ParseQuery(const GURL& url);
+
+// Returns a path that serves |original_path| with text that matches
+// |text_to_replace| with the corresponding values, and then returns the
+// resulting path in |replacement_path|.
+void GetFilePathWithReplacements(const std::string& original_path,
+ const base::StringPairs& text_to_replace,
+ std::string* replacement_path);
+
+// Handles |request| by serving a file from under |server_root|.
+scoped_ptr<HttpResponse> HandleFileRequest(const base::FilePath& server_root,
+ const HttpRequest& request);
+
+// Registers default handlers for use in tests.
+void RegisterDefaultHandlers(EmbeddedTestServer* server);
+
+} // namespace test_server
+} // namespace net
+
+#endif // NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HELPERS_H_

Powered by Google App Engine
This is Rietveld 408576698