List of usage examples for org.apache.http.client RedirectStrategy isRedirected
boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException;
From source file:org.sonatype.nexus.httpclient.NexusRedirectStrategyTest.java
@Test public void doFollowCrossSiteRedirects() throws ProtocolException { when(response.getStatusLine()).thenReturn(statusLine); final RedirectStrategy underTest = new NexusRedirectStrategy(); // simple cross redirect request = new HttpGet("http://hostA/dir"); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")).thenReturn(new BasicHeader("location", "http://hostB/dir")); assertThat(underTest.isRedirected(request, response, new BasicHttpContext()), is(true)); // cross redirect to dir (failed coz NEXUS-5744) request = new HttpGet("http://hostA/dir/"); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")).thenReturn(new BasicHeader("location", "http://hostB/dir/")); assertThat(underTest.isRedirected(request, response, new BasicHttpContext()), is(true)); }
From source file:org.sonatype.nexus.httpclient.internal.NexusRedirectStrategyTest.java
@Test public void doFollowCrossSiteRedirects() throws Exception { when(response.getStatusLine()).thenReturn(statusLine); final RedirectStrategy underTest = new NexusRedirectStrategy(); // simple cross redirect request = new HttpGet("http://hostA/dir"); when(statusLine.getStatusCode()).thenReturn(SC_MOVED_TEMPORARILY); when(response.getFirstHeader(argThat(equalToIgnoringCase(LOCATION)))) .thenReturn(new BasicHeader(LOCATION, "http://hostB/dir")); assertThat(underTest.isRedirected(request, response, new BasicHttpContext()), is(true)); // cross redirect to dir (failed coz NEXUS-5744) request = new HttpGet("http://hostA/dir/"); when(statusLine.getStatusCode()).thenReturn(SC_MOVED_TEMPORARILY); when(response.getFirstHeader(argThat(equalToIgnoringCase(LOCATION)))) .thenReturn(new BasicHeader(LOCATION, "http://hostB/dir/")); assertThat(underTest.isRedirected(request, response, new BasicHttpContext()), is(true)); }
From source file:org.sonatype.nexus.httpclient.internal.NexusRedirectStrategyTest.java
@Test public void doNotFollowRedirectsToDirIndex() throws Exception { when(response.getStatusLine()).thenReturn(statusLine); final RedirectStrategy underTest = new NexusRedirectStrategy(); HttpContext httpContext;/*from w w w . java2s .c om*/ // no location header request = new HttpGet("http://localhost/dir/fileA"); httpContext = new BasicHttpContext(); httpContext.setAttribute(CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(SC_OK); assertThat(underTest.isRedirected(request, response, httpContext), is(false)); // redirect to file request = new HttpGet("http://localhost/dir/fileA"); httpContext = new BasicHttpContext(); httpContext.setAttribute(CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(SC_MOVED_TEMPORARILY); when(response.getFirstHeader(argThat(equalToIgnoringCase(LOCATION)))) .thenReturn(new BasicHeader(LOCATION, "http://localhost/dir/fileB")); assertThat(underTest.isRedirected(request, response, httpContext), is(true)); // redirect to dir request = new HttpGet("http://localhost/dir"); httpContext = new BasicHttpContext(); httpContext.setAttribute(CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(SC_MOVED_TEMPORARILY); when(response.getFirstHeader(argThat(equalToIgnoringCase(LOCATION)))) .thenReturn(new BasicHeader(LOCATION, "http://localhost/dir/")); assertThat(underTest.isRedirected(request, response, httpContext), is(false)); }
From source file:org.sonatype.nexus.httpclient.NexusRedirectStrategyTest.java
@Test public void doNotFollowRedirectsToDirIndex() throws ProtocolException { when(response.getStatusLine()).thenReturn(statusLine); final RedirectStrategy underTest = new NexusRedirectStrategy(); HttpContext httpContext;/*from w ww . java 2 s . c o m*/ // no location header request = new HttpGet("http://localhost/dir/fileA"); httpContext = new BasicHttpContext(); httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); assertThat(underTest.isRedirected(request, response, httpContext), is(false)); // redirect to file request = new HttpGet("http://localhost/dir/fileA"); httpContext = new BasicHttpContext(); httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")) .thenReturn(new BasicHeader("location", "http://localhost/dir/fileB")); assertThat(underTest.isRedirected(request, response, httpContext), is(true)); // redirect to dir request = new HttpGet("http://localhost/dir"); httpContext = new BasicHttpContext(); httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")).thenReturn(new BasicHeader("location", "http://localhost/dir/")); assertThat(underTest.isRedirected(request, response, httpContext), is(false)); }
From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientManagerTest.java
@Test public void doFollowCrossSiteRedirects() throws ProtocolException { final RedirectStrategy underTest = httpClientManager.getProxyRepositoryRedirectStrategy(proxyRepository, globalRemoteStorageContext); // simple cross redirect request = new HttpGet("http://hostA/dir"); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")).thenReturn(new BasicHeader("location", "http://hostB/dir")); assertThat(underTest.isRedirected(request, response, new BasicHttpContext()), is(true)); // cross redirect to dir (failed coz NEXUS-5744) request = new HttpGet("http://hostA/dir/"); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")).thenReturn(new BasicHeader("location", "http://hostB/dir/")); assertThat(underTest.isRedirected(request, response, new BasicHttpContext()), is(true)); }
From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientManagerTest.java
@Test public void doNotFollowRedirectsToDirIndex() throws ProtocolException { final RedirectStrategy underTest = httpClientManager.getProxyRepositoryRedirectStrategy(proxyRepository, globalRemoteStorageContext); HttpContext httpContext;/* w w w . j a v a 2s . c o m*/ // no location header request = new HttpGet("http://localhost/dir/fileA"); httpContext = new BasicHttpContext(); httpContext.setAttribute(HttpClientRemoteStorage.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); assertThat(underTest.isRedirected(request, response, httpContext), is(false)); // redirect to file request = new HttpGet("http://localhost/dir/fileA"); httpContext = new BasicHttpContext(); httpContext.setAttribute(HttpClientRemoteStorage.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")) .thenReturn(new BasicHeader("location", "http://localhost/dir/fileB")); assertThat(underTest.isRedirected(request, response, httpContext), is(true)); // redirect to dir request = new HttpGet("http://localhost/dir"); httpContext = new BasicHttpContext(); httpContext.setAttribute(HttpClientRemoteStorage.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")).thenReturn(new BasicHeader("location", "http://localhost/dir/")); assertThat(underTest.isRedirected(request, response, httpContext), is(false)); }