Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AddCookiesInterceptor implements Interceptor {
- public static final String PREF_COOKIES = "PREF_COOKIES";
- private Context context;
- public AddCookiesInterceptor(Context context){
- this.context = context;
- }
- @Override
- public Response intercept(Chain chain) throws IOException {
- Request.Builder builder = chain.request().newBuilder();
- HashSet<String> preferences = (HashSet) PreferenceManager
- .getDefaultSharedPreferences(context).
- getStringSet(PREF_COOKIES, new HashSet<String>());
- for (String cookie : preferences) {
- builder.addHeader("Cookie", cookie);
- Log.e("OkHttp", "Adding Header: " + cookie); // This is done so I know which headers are being added; this interceptor is used after the normal logging of OkHttp
- }
- return chain.proceed(builder.build());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement