Commit cef484a7 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Make ExabyteResponse a default handler for EmbeddedTestServer.

ExabyteResponse  is almost never ending response (with an Extabyte
content-length). This response will be used in iOS tests, so it is useful
to make it default.

Bug: 614168,789585
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ie0edb7bbfc427bb83dc8bfbc9e143d1cd0e890e7
Reviewed-on: https://chromium-review.googlesource.com/890300
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarMisha Efimov <mef@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533071}
parent ba60a6c8
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "net/base/host_port_pair.h" #include "net/base/host_port_pair.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/embedded_test_server.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_request.h"
#include "net/test/embedded_test_server/http_response.h" #include "net/test/embedded_test_server/http_response.h"
...@@ -42,37 +43,9 @@ const char kEchoHeaderPath[] = "/echo_header"; ...@@ -42,37 +43,9 @@ const char kEchoHeaderPath[] = "/echo_header";
const char kEchoAllHeadersPath[] = "/echo_all_headers"; const char kEchoAllHeadersPath[] = "/echo_all_headers";
const char kEchoMethodPath[] = "/echo_method"; const char kEchoMethodPath[] = "/echo_method";
const char kRedirectToEchoBodyPath[] = "/redirect_to_echo_body"; const char kRedirectToEchoBodyPath[] = "/redirect_to_echo_body";
const char kExabyteResponsePath[] = "/exabyte_response";
net::EmbeddedTestServer* g_test_server = nullptr; net::EmbeddedTestServer* g_test_server = nullptr;
// A HttpResponse that is almost never ending (with an Extabyte content-length).
class ExabyteResponse : public net::test_server::BasicHttpResponse {
public:
ExabyteResponse() {}
void SendResponse(
const net::test_server::SendBytesCallback& send,
const net::test_server::SendCompleteCallback& done) override {
// Use 10^18 bytes (exabyte) as the content length so that the client will
// be expecting data.
send.Run("HTTP/1.1 200 OK\r\nContent-Length:1000000000000000000\r\n\r\n",
base::Bind(&ExabyteResponse::SendExabyte, send));
}
private:
// Keeps sending the word "echo" over and over again. It can go further to
// limit the response to exactly an exabyte, but it shouldn't be necessary
// for the purpose of testing.
static void SendExabyte(const net::test_server::SendBytesCallback& send) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(send, "echo",
base::Bind(&ExabyteResponse::SendExabyte, send)));
}
DISALLOW_COPY_AND_ASSIGN(ExabyteResponse);
};
std::unique_ptr<net::test_server::HttpResponse> NativeTestServerRequestHandler( std::unique_ptr<net::test_server::HttpResponse> NativeTestServerRequestHandler(
const net::test_server::HttpRequest& request) { const net::test_server::HttpRequest& request) {
DCHECK(g_test_server); DCHECK(g_test_server);
...@@ -121,11 +94,6 @@ std::unique_ptr<net::test_server::HttpResponse> NativeTestServerRequestHandler( ...@@ -121,11 +94,6 @@ std::unique_ptr<net::test_server::HttpResponse> NativeTestServerRequestHandler(
return std::unique_ptr<net::test_server::BasicHttpResponse>(); return std::unique_ptr<net::test_server::BasicHttpResponse>();
} }
std::unique_ptr<net::test_server::HttpResponse> HandleExabyteRequest(
const net::test_server::HttpRequest& request) {
return base::WrapUnique(new ExabyteResponse);
}
} // namespace } // namespace
jboolean JNI_NativeTestServer_StartNativeTestServer( jboolean JNI_NativeTestServer_StartNativeTestServer(
...@@ -144,15 +112,15 @@ jboolean JNI_NativeTestServer_StartNativeTestServer( ...@@ -144,15 +112,15 @@ jboolean JNI_NativeTestServer_StartNativeTestServer(
g_test_server = new net::EmbeddedTestServer(); g_test_server = new net::EmbeddedTestServer();
g_test_server->RegisterRequestHandler( g_test_server->RegisterRequestHandler(
base::Bind(&NativeTestServerRequestHandler)); base::Bind(&NativeTestServerRequestHandler));
g_test_server->RegisterDefaultHandler(
base::Bind(&net::test_server::HandlePrefixedRequest, kExabyteResponsePath,
base::Bind(&HandleExabyteRequest)));
base::FilePath test_files_root( base::FilePath test_files_root(
base::android::ConvertJavaStringToUTF8(env, jtest_files_root)); base::android::ConvertJavaStringToUTF8(env, jtest_files_root));
// Add a third handler for paths that NativeTestServerRequestHandler does not // Add a third handler for paths that NativeTestServerRequestHandler does not
// handle. // handle.
g_test_server->ServeFilesFromDirectory(test_files_root); g_test_server->ServeFilesFromDirectory(test_files_root);
RegisterDefaultHandlers(g_test_server);
return g_test_server->Start(); return g_test_server->Start();
} }
...@@ -230,7 +198,7 @@ ScopedJavaLocalRef<jstring> JNI_NativeTestServer_GetExabyteResponseURL( ...@@ -230,7 +198,7 @@ ScopedJavaLocalRef<jstring> JNI_NativeTestServer_GetExabyteResponseURL(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jclass>& jcaller) { const JavaParamRef<jclass>& jcaller) {
DCHECK(g_test_server); DCHECK(g_test_server);
GURL url = g_test_server->GetURL(kExabyteResponsePath); GURL url = g_test_server->GetURL("/exabyte_response");
return base::android::ConvertUTF8ToJavaString(env, url.spec()); return base::android::ConvertUTF8ToJavaString(env, url.spec());
} }
......
...@@ -646,6 +646,43 @@ std::unique_ptr<HttpResponse> HandleHungAfterHeadersResponse( ...@@ -646,6 +646,43 @@ std::unique_ptr<HttpResponse> HandleHungAfterHeadersResponse(
return std::make_unique<HungAfterHeadersHttpResponse>(); return std::make_unique<HungAfterHeadersHttpResponse>();
} }
// /exabyte_response
// A HttpResponse that is almost never ending (with an Exabyte content-length).
class ExabyteResponse : public net::test_server::BasicHttpResponse {
public:
ExabyteResponse() {}
void SendResponse(
const net::test_server::SendBytesCallback& send,
const net::test_server::SendCompleteCallback& done) override {
// Use 10^18 bytes (exabyte) as the content length so that the client will
// be expecting data.
send.Run("HTTP/1.1 200 OK\r\nContent-Length:1000000000000000000\r\n\r\n",
base::BindRepeating(&ExabyteResponse::SendExabyte, send));
}
private:
// Keeps sending the word "echo" over and over again. It can go further to
// limit the response to exactly an exabyte, but it shouldn't be necessary
// for the purpose of testing.
static void SendExabyte(const net::test_server::SendBytesCallback& send) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindRepeating(
send, "echo",
base::BindRepeating(&ExabyteResponse::SendExabyte, send)));
}
DISALLOW_COPY_AND_ASSIGN(ExabyteResponse);
};
// /exabyte_response
// Almost never ending response.
std::unique_ptr<net::test_server::HttpResponse> HandleExabyteResponse(
const net::test_server::HttpRequest& request) {
return std::make_unique<ExabyteResponse>();
}
// /gzip-body?<body> // /gzip-body?<body>
// Returns a response with a gzipped body of "<body>". Attempts to allocate // Returns a response with a gzipped body of "<body>". Attempts to allocate
// enough memory to contain the body, but DCHECKs if that fails. // enough memory to contain the body, but DCHECKs if that fails.
...@@ -745,6 +782,8 @@ void RegisterDefaultHandlers(EmbeddedTestServer* server) { ...@@ -745,6 +782,8 @@ void RegisterDefaultHandlers(EmbeddedTestServer* server) {
PREFIXED_HANDLER("/hung", &HandleHungResponse)); PREFIXED_HANDLER("/hung", &HandleHungResponse));
server->RegisterDefaultHandler( server->RegisterDefaultHandler(
PREFIXED_HANDLER("/hung-after-headers", &HandleHungAfterHeadersResponse)); PREFIXED_HANDLER("/hung-after-headers", &HandleHungAfterHeadersResponse));
server->RegisterDefaultHandler(
PREFIXED_HANDLER("/exabyte_response", &HandleExabyteResponse));
server->RegisterDefaultHandler( server->RegisterDefaultHandler(
PREFIXED_HANDLER("/gzip-body", &HandleGzipBody)); PREFIXED_HANDLER("/gzip-body", &HandleGzipBody));
server->RegisterDefaultHandler(PREFIXED_HANDLER("/self.pac", &HandleSelfPac)); server->RegisterDefaultHandler(PREFIXED_HANDLER("/self.pac", &HandleSelfPac));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment