-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to disagree server header? #1265
Comments
You're in luck. Be careful, this is dangerous. |
@swankjesse thanks. :D |
Hi swankjesse, is there any way to use this way with retrofit? I build this kind of client and set it to retrofit, but public static Client buildOkHttpClient(boolean cacheEnable) {
Cache cache = null;
OkHttpClient client = new OkHttpClient();
if (cacheEnable) {
File cacheDirectory = new File(MainApplication.getInstance().getCacheDir().getAbsolutePath(), "HttpCache");
try {
cache = new Cache(cacheDirectory, CACHE_SIZE);
} catch (IOException e) {
e.printStackTrace();
}
client.setCache(cache);
client.interceptors().add(REWRITE_CACHE_CONTROL_INTERCEPTOR);
}
return new OkClient(client);
}
/** Dangerous interceptor that rewrites the server's cache-control header. */
private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() {
@Override public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.header("Cache-Control", String.format("max-age=%d, max-stale=%d", MAX_AGE, MAX_STALE))
.build();
}
}; |
Are you comfortable using a snapshot build of Retrofit? The Retrofit code in git supports OkHttp headers, but that hasn't been released yet. (Probably will be released within 4–8 weeks.) |
@swankjesse Thank your replay. I change to |
I want to do some cache stuff in android client, but the server always return
Cache-Control: max-age=0, private, must-revalidate
, I wanna ignore it's Cache-Control.The text was updated successfully, but these errors were encountered: