Skip to content
Open
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 @@ -72,4 +72,10 @@ public interface IgnitedHttpRequest {
* Wi-Fi and 3G).
*/
public IgnitedHttpResponse send() throws ConnectException;

/**
* Sets the request to use the cookie store
*
*/
public IgnitedHttpResponse cookies();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.impl.client.BasicCookieStore;

import android.util.Log;

Expand All @@ -51,6 +53,8 @@ public abstract class IgnitedHttpRequestBase implements IgnitedHttpRequest,
protected HttpUriRequest request;

protected int maxRetries = MAX_RETRIES;

protected boolean useCookies = false;

private int oldSocketTimeout, oldConnTimeout;
private boolean timeoutChanged;
Expand Down Expand Up @@ -105,6 +109,11 @@ public IgnitedHttpRequest withTimeout(int timeout) {
return this;
}

@Override
public IgnitedHttpRequest cookies(boolean useCookies) {
this.useCookies = useCookies;
}

@Override
public IgnitedHttpResponse send() throws ConnectException {

Expand All @@ -115,6 +124,11 @@ public IgnitedHttpResponse send() throws ConnectException {

HttpContext context = new BasicHttpContext();

if (useCookies) {
BasicCookieStore cookieStore = new BasicCookieStore();
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

// Grab a coffee now and lean back, I'm not good at explaining stuff. This code realizes
// a second retry layer on top of HttpClient. Rationale: HttpClient.execute sometimes craps
// out even *before* the HttpRequestRetryHandler set above is called, e.g. on a
Expand Down