@Test public void maxRedirectsReached() throws Exception { AtomicInteger counter = new AtomicInteger(); when(httpClient.request(any(), any())).thenAnswer(a -> createRedirectResponse(counter.incrementAndGet())); final int maxRedirects = MAX_REDIRECTS; StreamingHttpClient client = newClient(new RedirectingHttpRequesterFilter(maxRedirects)); StreamingHttpRequest request = client.get("/path"); request.headers().set(HOST, "servicetalk.io"); verifyResponse(client, request, MOVED_PERMANENTLY, "/location-" + (maxRedirects + 1), maxRedirects + 1); }
private Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final HttpExecutionStrategy strategy, final StreamingHttpRequest request, final boolean onlyRelative) { final Single<StreamingHttpResponse> response = delegate.request(strategy, request); if (maxRedirects <= 0) { return response; } return new RedirectSingle(strategy, response, request, maxRedirects, delegate, onlyRelative); }
RedirectingHttpRequesterFilter implements StreamingHttpClientFilterFactory,
                                                             StreamingHttpConnectionFilterFactory,
                                                             HttpExecutionStrategyInfluencer { private Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final HttpExecutionStrategy strategy, final StreamingHttpRequest request, final boolean onlyRelative) { final Single<StreamingHttpResponse> response = delegate.request(strategy, request); if (maxRedirects <= 0) { return response; } return new RedirectSingle(strategy, response, request, maxRedirects, delegate, onlyRelative); } }
RedirectingHttpRequesterFilter implements StreamingHttpClientFilterFactory,
                                                             StreamingHttpConnectionFilterFactory,
                                                             HttpExecutionStrategyInfluencer { private Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final HttpExecutionStrategy strategy, final StreamingHttpRequest request, final boolean onlyRelative) { final Single<StreamingHttpResponse> response = delegate.request(strategy, request); if (maxRedirects <= 0) { return response; } return new RedirectSingle(strategy, response, request, maxRedirects, delegate, onlyRelative); } RedirectingHttpRequesterFilter();  RedirectingHttpRequesterFilter(final int maxRedirects);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final int maxRedirects);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final boolean onlyRelativeConnection);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final boolean onlyRelativeConnection,
                                          final int maxRedirects); }
RedirectingHttpRequesterFilter implements StreamingHttpClientFilterFactory,
                                                             StreamingHttpConnectionFilterFactory,
                                                             HttpExecutionStrategyInfluencer { private Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final HttpExecutionStrategy strategy, final StreamingHttpRequest request, final boolean onlyRelative) { final Single<StreamingHttpResponse> response = delegate.request(strategy, request); if (maxRedirects <= 0) { return response; } return new RedirectSingle(strategy, response, request, maxRedirects, delegate, onlyRelative); } RedirectingHttpRequesterFilter();  RedirectingHttpRequesterFilter(final int maxRedirects);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final int maxRedirects);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final boolean onlyRelativeConnection);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final boolean onlyRelativeConnection,
                                          final int maxRedirects); @Override StreamingHttpClientFilter create(final FilterableStreamingHttpClient client); @Override StreamingHttpConnectionFilter create(final FilterableStreamingHttpConnection connection); @Override HttpExecutionStrategy influenceStrategy(final HttpExecutionStrategy strategy); }
RedirectingHttpRequesterFilter implements StreamingHttpClientFilterFactory,
                                                             StreamingHttpConnectionFilterFactory,
                                                             HttpExecutionStrategyInfluencer { private Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final HttpExecutionStrategy strategy, final StreamingHttpRequest request, final boolean onlyRelative) { final Single<StreamingHttpResponse> response = delegate.request(strategy, request); if (maxRedirects <= 0) { return response; } return new RedirectSingle(strategy, response, request, maxRedirects, delegate, onlyRelative); } RedirectingHttpRequesterFilter();  RedirectingHttpRequesterFilter(final int maxRedirects);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final int maxRedirects);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final boolean onlyRelativeConnection);  RedirectingHttpRequesterFilter(final boolean onlyRelativeClient,
                                          final boolean onlyRelativeConnection,
                                          final int maxRedirects); @Override StreamingHttpClientFilter create(final FilterableStreamingHttpClient client); @Override StreamingHttpConnectionFilter create(final FilterableStreamingHttpConnection connection); @Override HttpExecutionStrategy influenceStrategy(final HttpExecutionStrategy strategy);  }