|
22 | 22 | import static org.mockito.Mockito.mock;
|
23 | 23 | import static org.mockito.Mockito.when;
|
24 | 24 |
|
| 25 | +import com.google.api.client.http.GenericUrl; |
25 | 26 | import com.google.api.client.http.LowLevelHttpResponse;
|
26 | 27 | import com.google.api.client.util.ByteArrayStreamingContent;
|
| 28 | +import com.sun.net.httpserver.HttpExchange; |
| 29 | +import com.sun.net.httpserver.HttpHandler; |
| 30 | +import com.sun.net.httpserver.HttpServer; |
27 | 31 | import java.io.IOException;
|
| 32 | +import java.io.OutputStream; |
| 33 | +import java.net.InetSocketAddress; |
28 | 34 | import java.nio.charset.StandardCharsets;
|
| 35 | +import java.util.Random; |
29 | 36 | import java.util.concurrent.atomic.AtomicBoolean;
|
30 | 37 | import java.util.concurrent.atomic.AtomicInteger;
|
31 | 38 | import org.apache.http.Header;
|
@@ -175,4 +182,33 @@ public void process(HttpRequest request, HttpContext context)
|
175 | 182 | }
|
176 | 183 | assertTrue("Expected to have called our test interceptor", interceptorCalled.get());
|
177 | 184 | }
|
| 185 | + |
| 186 | + @Test |
| 187 | + public void testNormalizedUrl() throws IOException { |
| 188 | + HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); |
| 189 | + server.createContext( |
| 190 | + "/", |
| 191 | + new HttpHandler() { |
| 192 | + @Override |
| 193 | + public void handle(HttpExchange httpExchange) throws IOException { |
| 194 | + byte[] response = httpExchange.getRequestURI().toString().getBytes(); |
| 195 | + httpExchange.sendResponseHeaders(200, response.length); |
| 196 | + try (OutputStream out = httpExchange.getResponseBody()) { |
| 197 | + out.write(response); |
| 198 | + } |
| 199 | + } |
| 200 | + }); |
| 201 | + server.start(); |
| 202 | + |
| 203 | + ApacheHttpTransport transport = new ApacheHttpTransport(); |
| 204 | + GenericUrl testUrl = new GenericUrl("http://localhost/foo//bar"); |
| 205 | + testUrl.setPort(server.getAddress().getPort()); |
| 206 | + com.google.api.client.http.HttpResponse response = |
| 207 | + transport |
| 208 | + .createRequestFactory() |
| 209 | + .buildGetRequest(testUrl) |
| 210 | + .execute(); |
| 211 | + assertEquals(200, response.getStatusCode()); |
| 212 | + assertEquals("/foo//bar", response.parseAsString()); |
| 213 | + } |
178 | 214 | }
|
0 commit comments