Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable uri normalization in ApacheHttpRequest #804

Merged
merged 4 commits into from Aug 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,10 +22,17 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.util.ByteArrayStreamingContent;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.http.Header;
Expand Down Expand Up @@ -175,4 +182,32 @@ public void process(HttpRequest request, HttpContext context)
}
assertTrue("Expected to have called our test interceptor", interceptorCalled.get());
}

@Test
public void testNormalizedUrl() throws IOException {
int port = 8000 + new Random().nextInt(1000);
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
server.createContext(
"/",
new HttpHandler() {
@Override
public void handle(HttpExchange httpExchange) throws IOException {
byte[] response = httpExchange.getRequestURI().toString().getBytes();
httpExchange.sendResponseHeaders(200, response.length);
OutputStream os = httpExchange.getResponseBody();
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
os.write(response);
os.close();
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
}
});
server.start();

ApacheHttpTransport transport = new ApacheHttpTransport();
com.google.api.client.http.HttpResponse response =
transport
.createRequestFactory()
.buildGetRequest(new GenericUrl("http://localhost:" + port + "/foo//bar"))
.execute();
assertEquals(200, response.getStatusCode());
assertEquals("/foo//bar", response.parseAsString());
}
}