Unverified Commit 10771d3a authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #765 from capnproto/http-client-no-rewrite-url

Multi-host HttpClient shouldn't rewrite URL.
parents ab197cf8 597c0c72
......@@ -1418,7 +1418,7 @@ KJ_TEST("HttpInputStream requests") {
KJ_CONTEXT(testCase.raw);
KJ_ASSERT(input->awaitNextMessage().wait(waitScope));
auto req = input->readRequest().wait(waitScope);
KJ_EXPECT(req.method == testCase.method);
KJ_EXPECT(req.url == testCase.path);
......@@ -3109,14 +3109,16 @@ KJ_TEST("HttpClient multi host") {
uint i = 0;
auto doRequest = [&](bool tls, uint port) {
uint n = i++;
// We stick a double-slash in the URL to test that it doesn't get coalesced into one slash,
// which was a bug in the past.
return client->request(HttpMethod::GET,
kj::str((tls ? "https://localhost:" : "http://localhost:"), port, '/', n),
kj::str((tls ? "https://localhost:" : "http://localhost:"), port, "//", n),
HttpHeaders(headerTable)).response
.then([](HttpClient::Response&& response) {
auto promise = response.body->readAllText();
return promise.attach(kj::mv(response.body));
}).then([n, port](kj::String body) {
KJ_EXPECT(body == kj::str("localhost:", port, ":/", n), body, port, n);
KJ_EXPECT(body == kj::str("localhost:", port, "://", n), body, port, n);
});
};
......
......@@ -3699,7 +3699,13 @@ public:
Request request(HttpMethod method, kj::StringPtr url, const HttpHeaders& headers,
kj::Maybe<uint64_t> expectedBodySize = nullptr) override {
auto parsed = Url::parse(url, Url::HTTP_PROXY_REQUEST);
// We need to parse the proxy-style URL to convert it to host-style.
// Use URL parsing options that avoid unnecessary rewrites.
Url::Options urlOptions;
urlOptions.allowEmpty = true;
urlOptions.percentDecode = false;
auto parsed = Url::parse(url, Url::HTTP_PROXY_REQUEST, urlOptions);
auto path = parsed.toString(Url::HTTP_REQUEST);
auto headersCopy = headers.clone();
headersCopy.set(HttpHeaderId::HOST, parsed.host);
......@@ -3708,7 +3714,13 @@ public:
kj::Promise<WebSocketResponse> openWebSocket(
kj::StringPtr url, const HttpHeaders& headers) override {
auto parsed = Url::parse(url, Url::HTTP_PROXY_REQUEST);
// We need to parse the proxy-style URL to convert it to host-style.
// Use URL parsing options that avoid unnecessary rewrites.
Url::Options urlOptions;
urlOptions.allowEmpty = true;
urlOptions.percentDecode = false;
auto parsed = Url::parse(url, Url::HTTP_PROXY_REQUEST, urlOptions);
auto path = parsed.toString(Url::HTTP_REQUEST);
auto headersCopy = headers.clone();
headersCopy.set(HttpHeaderId::HOST, parsed.host);
......
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