Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public class AddCookiesInterceptor implements Interceptor {
  2.  
  3. public static final String PREF_COOKIES = "PREF_COOKIES";
  4. private Context context;
  5.  
  6. public AddCookiesInterceptor(Context context){
  7. this.context = context;
  8. }
  9.  
  10. @Override
  11. public Response intercept(Chain chain) throws IOException {
  12. Request.Builder builder = chain.request().newBuilder();
  13.  
  14. HashSet<String> preferences = (HashSet) PreferenceManager
  15. .getDefaultSharedPreferences(context).
  16. getStringSet(PREF_COOKIES, new HashSet<String>());
  17.  
  18. for (String cookie : preferences) {
  19. builder.addHeader("Cookie", cookie);
  20. 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
  21. }
  22. return chain.proceed(builder.build());
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement