Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ReceivedCookiesInterceptor implements Interceptor {
- public static final String PREF_COOKIES = "PREF_COOKIES";
- private Context context;
- public ReceivedCookiesInterceptor(Context context){
- this.context = context;
- }
- @Override
- public Response intercept(Chain chain) throws IOException {
- Response originalResponse = chain.proceed(chain.request());
- if (!originalResponse.headers("Set-Cookie").isEmpty()) {
- HashSet<String> cookies = new HashSet<>();
- for (String header : originalResponse.headers("Set-Cookie")) {
- cookies.add(header);
- }
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .putStringSet(PREF_COOKIES, cookies)
- .apply();
- }
- return originalResponse;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement