Skip to content

Let Netty Webclient optionally follow redirects. #1618

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,41 @@
public class ReactorClientHttpConnector implements ClientHttpConnector {

private final HttpClient httpClient;
private final boolean followRedirects;


/**
* Create a Reactor Netty {@link ClientHttpConnector}
* with default {@link ClientOptions} and HTTP compression support enabled.
*/
public ReactorClientHttpConnector() {
this.httpClient = HttpClient.builder()
.options(options -> options.compression(true))
.build();
this(false);
}

/**
* Create a Reactor Netty {@link ClientHttpConnector}
* with default {@link ClientOptions} and HTTP compression support enabled
* which will optionally follows redirects.
*/
public ReactorClientHttpConnector(boolean followRedirects) {
this(options -> options.compression(true), followRedirects);
}

/**
* Create a Reactor Netty {@link ClientHttpConnector} with the given
* {@link HttpClientOptions.Builder}
*/
public ReactorClientHttpConnector(Consumer<? super HttpClientOptions.Builder> clientOptions) {
this(clientOptions, false);
}

/**
* Create a Reactor Netty {@link ClientHttpConnector} with the given
* {@link HttpClientOptions.Builder} which optionally follows redirects.
*/
public ReactorClientHttpConnector(Consumer<? super HttpClientOptions.Builder> clientOptions, boolean followRedirects) {
this.httpClient = HttpClient.create(clientOptions);
this.followRedirects = followRedirects;
}


Expand All @@ -80,7 +97,7 @@ private io.netty.handler.codec.http.HttpMethod adaptHttpMethod(HttpMethod method
}

private ReactorClientHttpRequest adaptRequest(HttpMethod method, URI uri, HttpClientRequest request) {
return new ReactorClientHttpRequest(method, uri, request);
return new ReactorClientHttpRequest(method, uri, request, followRedirects);
}

private ClientHttpResponse adaptResponse(HttpClientResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ class ReactorClientHttpRequest extends AbstractClientHttpRequest implements Zero


public ReactorClientHttpRequest(HttpMethod httpMethod, URI uri,
HttpClientRequest httpRequest) {
HttpClientRequest httpRequest, boolean followRedirects) {
this.httpMethod = httpMethod;
this.uri = uri;
this.httpRequest = httpRequest.failOnClientError(false).failOnServerError(false);
this.bufferFactory = new NettyDataBufferFactory(httpRequest.alloc());

if (followRedirects) {
this.httpRequest.followRedirect();
}
}


Expand Down