Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. public class ReceivedCookiesInterceptor implements Interceptor {
  2.  
  3.     public static final String PREF_COOKIES = "PREF_COOKIES";
  4.     private Context context;
  5.  
  6.     public ReceivedCookiesInterceptor(Context context){
  7.         this.context = context;
  8.     }
  9.  
  10.     @Override
  11.     public Response intercept(Chain chain)  throws IOException  {
  12.         Response originalResponse = chain.proceed(chain.request());
  13.  
  14.         if (!originalResponse.headers("Set-Cookie").isEmpty()) {
  15.             HashSet<String> cookies = new HashSet<>();
  16.  
  17.             for (String header : originalResponse.headers("Set-Cookie")) {
  18.                 cookies.add(header);
  19.             }
  20.             PreferenceManager.getDefaultSharedPreferences(context).edit()
  21.                     .putStringSet(PREF_COOKIES, cookies)
  22.                     .apply();
  23.         }
  24.         return originalResponse;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement