Skip to content
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

fixes issue with useRawUrl, queryString decode/encode and redirecting #14

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -9,7 +9,7 @@
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<name>Asynchronous Http Client</name>
<version>1.6.4</version>
<version>1.6.4_rawUrlFix</version>
<packaging>jar</packaging>
<description>
Async Http Client library purpose is to allow Java applications to easily execute HTTP requests and
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/ning/http/client/AsyncHttpClient.java
Expand Up @@ -215,8 +215,8 @@ public class BoundRequestBuilder extends RequestBuilderBase<BoundRequestBuilder>
*/
protected String baseURL;

private BoundRequestBuilder(String reqType) {
super(BoundRequestBuilder.class, reqType);
private BoundRequestBuilder(String reqType, boolean useRawUrl) {
super(BoundRequestBuilder.class, reqType, useRawUrl);
}

private BoundRequestBuilder(Request prototype) {
Expand Down Expand Up @@ -557,7 +557,7 @@ private final static AsyncHttpProvider loadDefaultProvider(String className, Asy
}

protected BoundRequestBuilder requestBuilder(String reqType, String url) {
return new BoundRequestBuilder(reqType).setUrl(url).setSignatureCalculator(signatureCalculator);
return new BoundRequestBuilder(reqType, config.isUseRawUrl()).setUrl(url).setSignatureCalculator(signatureCalculator);
}

protected BoundRequestBuilder requestBuilder(Request prototype) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ning/http/client/Request.java
Expand Up @@ -190,4 +190,6 @@ public static interface EntityWriter {
*/
public String getBodyEncoding();

public boolean isUseRawUrl();

}
9 changes: 7 additions & 2 deletions src/main/java/com/ning/http/client/RequestBuilder.java
Expand Up @@ -25,12 +25,17 @@
* Builder for a {@link Request}.
*/
public class RequestBuilder extends RequestBuilderBase<RequestBuilder> {

public RequestBuilder() {
super(RequestBuilder.class, "GET");
super(RequestBuilder.class, "GET", false);
}

public RequestBuilder(String method) {
super(RequestBuilder.class, method);
super(RequestBuilder.class, method, false);
}

public RequestBuilder(String method, boolean useRawUrl) {
super(RequestBuilder.class, method, useRawUrl);
}

public RequestBuilder(Request prototype) {
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/com/ning/http/client/RequestBuilderBase.java
Expand Up @@ -58,8 +58,10 @@ private static final class RequestImpl implements Request {
private PerRequestConfig perRequestConfig;
private long rangeOffset = 0;
public String charset;
private boolean useRawUrl = false;

public RequestImpl() {
public RequestImpl(boolean useRawUrl) {
this.useRawUrl = useRawUrl;
}

public RequestImpl(Request prototype) {
Expand All @@ -86,6 +88,7 @@ public RequestImpl(Request prototype) {
this.perRequestConfig = prototype.getPerRequestConfig();
this.rangeOffset = prototype.getRangeOffset();
this.charset = prototype.getBodyEncoding();
this.useRawUrl = prototype.isUseRawUrl();
}
}

Expand Down Expand Up @@ -274,20 +277,27 @@ public String toString() {

return sb.toString();
}

public boolean isUseRawUrl() {
return useRawUrl;
}
}

private final Class<T> derived;
protected final RequestImpl request;
protected boolean useRawUrl = false;

protected RequestBuilderBase(Class<T> derived, String method) {
protected RequestBuilderBase(Class<T> derived, String method, boolean rawUrls) {
this.derived = derived;
request = new RequestImpl();
request = new RequestImpl(rawUrls);
request.method = method;
this.useRawUrl = rawUrls;
}

protected RequestBuilderBase(Class<T> derived, Request prototype) {
this.derived = derived;
request = new RequestImpl(prototype);
this.useRawUrl = prototype.isUseRawUrl();
}

public T setUrl(String url) {
Expand Down Expand Up @@ -330,7 +340,11 @@ private String buildUrl(String url) {
addQueryParameter(query, null);
}else{
try {
addQueryParameter(URLDecoder.decode(query.substring(0, pos), "UTF-8") , URLDecoder.decode(query.substring(pos +1), "UTF-8"));
if (this.useRawUrl) {
addQueryParameter(query.substring(0, pos) , query.substring(pos +1));
} else {
addQueryParameter(URLDecoder.decode(query.substring(0, pos), "UTF-8") , URLDecoder.decode(query.substring(pos +1), "UTF-8"));
}
}
catch ( UnsupportedEncodingException e ) {
throw new RuntimeException(e);
Expand Down
Expand Up @@ -403,7 +403,7 @@ public final static class Builder implements DerivedBuilder {
private SimpleAHCTransferListener listener = null;

public Builder() {
requestBuilder = new RequestBuilder("GET");
requestBuilder = new RequestBuilder("GET", false);
}

private Builder(SimpleAsyncHttpClient client) {
Expand Down