Is it possible to disable following redirects in OkHttp 2.0?

In Android, I'd like to use the new OkHttp 2.0 to request some URLs, but I'd like more control over redirects. I've already found the option to enable or disable following HTTPS → HTTP or HTTP → HTTPS redirects, but I'd like to not follow any redirects, so I can update my GUI as soon as possible, and choose whether to follow them from application logic. I don't see an option to do this. Is it possible, and if so, how can I achieve this?


Yes it is possible in version 2.3.0

final OkHttpClient client = new OkHttpClient();
client.setFollowRedirects(false);

For 3.x

OkHttpClient client = new OkHttpClient().newBuilder()
                                            .followRedirects(false)
                                            .followSslRedirects(false)
                                            .build();

Seems like it isn't possible, but it will supposedly make it into the next release, at least according to some of these comments on a related issue on Github.

Edit: It looks like it could be possible through OkUrlFactory, which is part of the okhttp-urlconnection submodule (still haven't figured out the actual purpose of this, but it looks like an Http(s)UrlConnection replacement).

Edit 2: Actually, hang on; it looks like it is implemented on master. However, it also looks like this didn't make it into the 2.0.0 release snapshot.


Try

client.setFollowRedirects(true|false);

or, if using the HTTPUrlConnection module:

HTTPUrlConnection.setFollowRedirects(true|false);