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

java.lang.UnsupportedOperationException while adding interceptor #2219

Closed
outofdate opened this issue Jan 9, 2016 · 1 comment
Closed

java.lang.UnsupportedOperationException while adding interceptor #2219

outofdate opened this issue Jan 9, 2016 · 1 comment

Comments

@outofdate
Copy link

3.0.0-RC1
This chunk of code is throwing exception.
So i found it out when migrating to okhttp3.

 client.interceptors().add(new Interceptor() {
            @Override
            public okhttp3.Response intercept(Chain chain) throws IOException {
                Request request = chain.request();
                Request.Builder requestBuilder = request.newBuilder()
                        .addHeader("Authorization", authPrefs.getString(Properties.ApiProperties.TOKEN, "null"))
                        .method(request.method(), request.body());

                request = requestBuilder.build();
                return chain.proceed(request);
            }
        });

Version 2.7.0 works fine for me.

@artem-zinnatullin
Copy link
Contributor

This part of OkHttp is now immutable, please use OkHttpClient.Builder and
add interceptor when you create OkHttpClient instance.

Something like this:

new OkHttpClient.Builder().addInterceptor(...).build()

On Sat, Jan 9, 2016, 14:19 outofdate [email protected] wrote:

300-RC1
This chunk of code is throwing exception
So i found it out when migrating to okhttp3

clientinterceptors()add(new Interceptor() {
@OverRide
public okhttp3Response intercept(Chain chain) throws IOException {
Request request = chainrequest();
RequestBuilder requestBuilder = requestnewBuilder()
addHeader("Authorization", authPrefsgetString(PropertiesApiPropertiesTOKEN, "null"))
method(requestmethod(), requestbody());

            request = requestBuilderbuild();
            return chainproceed(request);
        }
    });

Version 270 works fine for me


Reply to this email directly or view it on GitHub
#2219.

@artem_zin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants