Skip to content

Commit

Permalink
[RESTEASY-3324] Enable redirects using property.
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Huginn committed Jul 18, 2023
1 parent 629570e commit b5e1405
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public enum HostnameVerificationPolicy {
*/
public static final String PROPERTY_PROXY_SCHEME = "org.jboss.resteasy.jaxrs.client.proxy.scheme";

public static final String PROPERTY_FOLLOW_REDIRECTS = "org.jboss.resteasy.jaxrs.client.follow-redirects";

/**
* Changing the providerFactory will wipe clean any registered components or properties.
*
Expand Down Expand Up @@ -279,5 +281,7 @@ public enum HostnameVerificationPolicy {
*/
public abstract ResteasyClientBuilder setFollowRedirects(boolean followRedirects);

public abstract ResteasyClientBuilder setFollowRedirects();

public abstract boolean isFollowRedirects();
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,7 @@ public interface Messages {
@Message(id = BASE + 194, value = "No content type found in response. Cannot extract the response value.")
@Signature(messageIndex = 1, value = { Response.class, String.class })
ResponseProcessingException noContentTypeFound(@Param Response response);

@Message(id = BASE + 195, value = "Unable to set follow redirects policy.")
String unableToSetFollowRedirects();
}
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,25 @@ public ResteasyClientBuilder setFollowRedirects(boolean followRedirects) {
return this;
}

@Override
public ResteasyClientBuilder setFollowRedirects() {
ClientConfiguration config = new ClientConfiguration(getProviderFactory());
try {
if (config.hasProperty(ResteasyClientBuilder.PROPERTY_FOLLOW_REDIRECTS)) {
Object enabled = config.getProperty(ResteasyClientBuilder.PROPERTY_FOLLOW_REDIRECTS);
if (enabled instanceof Boolean) {
this.followRedirects = (Boolean) enabled;
} else if (enabled instanceof String) {
this.followRedirects = Boolean.parseBoolean((String) enabled);
}
}
} catch (Exception e) {
// catch possible exceptions (in this case we do not set follow-redirects at all)
LogMessages.LOGGER.warn(Messages.MESSAGES.unableToSetFollowRedirects(), e);
}
return this;
}

@Override
public boolean isFollowRedirects() {
return followRedirects;
Expand Down

0 comments on commit b5e1405

Please sign in to comment.