Skip to content

Commit

Permalink
fixed redirect problem (does not work for POST)
Browse files Browse the repository at this point in the history
  • Loading branch information
orbiter committed Apr 12, 2008
1 parent 8313d58 commit 8dd35f7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion source/de/anomic/http/JakartaCommonsHttpClient.java
Expand Up @@ -203,6 +203,7 @@ public String getUserAgent() {
*/
public JakartaCommonsHttpResponse GET(final String uri) throws IOException {
final HttpMethod get = new GetMethod(uri);
get.setFollowRedirects(followRedirects);
return execute(get);
}

Expand All @@ -217,6 +218,7 @@ public JakartaCommonsHttpResponse GET(final String uri) throws IOException {
public JakartaCommonsHttpResponse HEAD(final String uri) throws IOException {
assert uri != null : "precondition violated: uri != null";
final HttpMethod head = new HeadMethod(uri);
head.setFollowRedirects(followRedirects);
return execute(head);
}

Expand All @@ -235,6 +237,7 @@ public JakartaCommonsHttpResponse POST(final String uri, final InputStream ins)
assert ins != null : "precondition violated: ins != null";
final PostMethod post = new PostMethod(uri);
post.setRequestEntity(new InputStreamRequestEntity(ins));
post.setFollowRedirects(false); // redirects in POST cause a "Entity enclosing requests cannot be redirected without user intervention" - exception
return execute(post);
}

Expand Down Expand Up @@ -290,6 +293,7 @@ public JakartaCommonsHttpResponse POST(final String uri, final List<Part> files)
parts = new Part[0];
}
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
post.setFollowRedirects(false); // redirects in POST cause a "Entity enclosing requests cannot be redirected without user intervention" - exception
return execute(post);
}

Expand All @@ -302,6 +306,7 @@ public JakartaCommonsHttpResponse CONNECT(final String host, final int port) thr
final HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost(host, port);
final HttpMethod connect = new ConnectMethod(hostConfig);
connect.setFollowRedirects(false); // there are no redirects possible for CONNECT commands as far as I know.
return execute(connect);
}

Expand Down Expand Up @@ -391,7 +396,6 @@ private static Header[] convertHeaders(final httpHeader requestHeader) {
*/
private JakartaCommonsHttpResponse execute(final HttpMethod method) throws IOException, HttpException {
assert method != null : "precondition violated: method != null";
method.setFollowRedirects(followRedirects);
// set header
for (final Header header : headers) {
method.setRequestHeader(header);
Expand Down

0 comments on commit 8dd35f7

Please sign in to comment.