uri = request.getUri(); } catch (final URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex);
@Override public URI getUri() throws URISyntaxException { return message.getUri(); }
@Override public URI getUri() throws URISyntaxException { return message.getUri(); }
@Override public URI getLocationURI( final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException { Args.notNull(request, "HTTP request"); Args.notNull(response, "HTTP response"); Args.notNull(context, "HTTP context"); //get the location header to find out where to redirect to final Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { throw new HttpException("Redirect location is missing"); } final String location = locationHeader.getValue(); URI uri = createLocationURI(location); try { if (!uri.isAbsolute()) { // Resolve location URI uri = URIUtils.resolve(request.getUri(), uri); } } catch (final URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } return uri; }
private static PasswordAuthentication getSystemCreds( final String protocol, final AuthScope authscope, final Authenticator.RequestorType requestorType, final HttpClientContext context) { final HttpRequest request = context != null ? context.getRequest() : null; URL targetHostURL; try { final URI uri = request != null ? request.getUri() : null; targetHostURL = uri != null ? uri.toURL() : null; } catch (final URISyntaxException | MalformedURLException ignore) { targetHostURL = null; } // use null addr, because the authentication fails if it does not exactly match the expected realm's host return Authenticator.requestPasswordAuthentication( authscope.getHost(), null, authscope.getPort(), protocol, authscope.getRealm(), translateAuthScheme(authscope.getAuthScheme()), targetHostURL, requestorType); }
URI uri = request.getUri(); if (!uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, route.getTargetHost(), true);
@Test public void testRequestWithRelativeURI() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", new URI("/stuff")); Assert.assertEquals("GET", request.getMethod()); Assert.assertEquals("/stuff", request.getPath()); Assert.assertEquals(null, request.getAuthority()); Assert.assertEquals(new URI("/stuff"), request.getUri()); }
@Test public void testRequestWithUserInfo() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", new URI("https://user:pwd@host:9443/stuff?param=value")); Assert.assertEquals("GET", request.getMethod()); Assert.assertEquals("/stuff?param=value", request.getPath()); Assert.assertEquals(new URIAuthority("user:pwd", "host", 9443), request.getAuthority()); Assert.assertEquals("https", request.getScheme()); Assert.assertEquals(new URI("https://host:9443/stuff?param=value"), request.getUri()); }
@Test public void testRequestWithNoPath() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", new URI("http://host")); Assert.assertEquals("GET", request.getMethod()); Assert.assertEquals("/", request.getPath()); Assert.assertEquals(new URIAuthority("host"), request.getAuthority()); Assert.assertEquals("http", request.getScheme()); Assert.assertEquals(new URI("http://host/"), request.getUri()); }
@Test public void testRequestWithAbsoluteURI() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", new URI("https://host:9443/stuff?param=value")); Assert.assertEquals("GET", request.getMethod()); Assert.assertEquals("/stuff?param=value", request.getPath()); Assert.assertEquals(new URIAuthority("host", 9443), request.getAuthority()); Assert.assertEquals("https", request.getScheme()); Assert.assertEquals(new URI("https://host:9443/stuff?param=value"), request.getUri()); }
@Test public void testRequestBasics() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", "/stuff"); Assert.assertEquals("GET", request.getMethod()); Assert.assertEquals("/stuff", request.getPath()); Assert.assertEquals(null, request.getAuthority()); Assert.assertEquals(new URI("/stuff"), request.getUri()); }
@Test public void testRequestWithAuthority() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("http", "somehost", -1), "/stuff"); Assert.assertEquals("GET", request.getMethod()); Assert.assertEquals("/stuff", request.getPath()); Assert.assertEquals(new URIAuthority("somehost"), request.getAuthority()); Assert.assertEquals(new URI("http://somehost/stuff"), request.getUri()); }
@Test public void testRequestWithAbsoluteURIAsPath() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", "https://host:9443/stuff?param=value"); Assert.assertEquals("GET", request.getMethod()); Assert.assertEquals("/stuff?param=value", request.getPath()); Assert.assertEquals(new URIAuthority("host", 9443), request.getAuthority()); Assert.assertEquals("https", request.getScheme()); Assert.assertEquals(new URI("https://host:9443/stuff?param=value"), request.getUri()); }
@Test public void testRequestWithAuthorityRelativePath() throws Exception { final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("http", "somehost", -1), "stuff"); Assert.assertEquals("GET", request.getMethod()); Assert.assertEquals("stuff", request.getPath()); Assert.assertEquals(new URIAuthority("somehost"), request.getAuthority()); Assert.assertEquals(new URI("http://somehost/stuff"), request.getUri()); }