Skip to content

Instantly share code, notes, and snippets.

@leeyc09
Created January 26, 2016 02:29
Show Gist options
  • Save leeyc09/55fba0a7b29e8f788dd0 to your computer and use it in GitHub Desktop.
Save leeyc09/55fba0a7b29e8f788dd0 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.util.HashSet;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class ReceivedCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) {
Request request = chain.request();
Response originalResponse = null;
try {
originalResponse = chain.proceed(request);
if (!originalResponse.headers("Set-Cookie").isEmpty()) {
HashSet<String> cookies = new HashSet<>();
for (String header : originalResponse.headers("Set-Cookie")) {
cookies.add(header);
}
//프리퍼런스에 쿠키 값을 저장합니다.
PreferenceHelper.getDefaultPreferences().edit().putStringSet(PreferenceHelper.PREF_directfolder_COOKIES, cookies).apply();
}
} catch (IOException e) {
e.printStackTrace();
}
return originalResponse;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment