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
Enable Manual Response Caching #3488
Comments
This is actually a feature we recently discussed adding. Can I ask what your use case would be? On first glance this doesn't seem to be a very useful capability. The use case you mention, caching, is already possible with the We discussed adding a general |
I thought the same thing @Alexandredenis35. It's just a very complex feature to support. I'm with @jshier, do you have any actual use cases? I myself didn't which made it difficult to try to justify. |
I would like to cache a response that the server does not allow, by removing the |
@Alexandredenis35 As I said, you should already be able to do that with the |
Yes, indeed I have already implemented a
The response has to be considered for caching before manipulate it. |
Ah yes, sorry. Unfortunately there's no other way to hook into // Assuming Session is in scope somewhere.
session.request(...).responseDecodable(of: Type.self) { response in
// Unwrap urlRequest, httpResponse, data, and check for success.
// Modify the httpResponse to remove the caching attributes.
let cachedResponse = CachedURLResponse(response: httpResponse, data: data)
session.configuration.urlCache.storeCachedResponse(cachedResponse, for: urlRequest)
} That should allow future requests using the same Given this limitation of |
Thinking about this more, proper integration of manual caching into Alamofire is deeply impacted by our response serializer APIs and the fact that My current thinking is that we'd create a wrapper protocol for our serializers which would allow manual caching after running the serializer. It would look to the rest of the system that's it's just a response serializer with additional parameters injected. Perhaps something like: ManuallyCaching(DecodableResponseSerializer()) with a convenience method: request.manuallyCachingResponse(.decodable(of: Type.self)) { response in } But this requires further investigation. |
Problem
I would like to retrieve the response returned by the webservice and modify its header before it is interpreted by the Alamofire library such as a Response Interceptor. This functionality seems to be present using a
ResponseCacher
to modify a response before caching it.However, if you want to modify the headers to allow the response to be cached, there is currently no solution.
Feature Request
Have the ability to intercept the response and modify any header. This feature is available with the OkHttp library on Android https://square.github.io/okhttp/interceptors/#rewriting-responses.
Value to Alamofire
As mentioned above, this would allow the behavior of the response to be changed on the client side and, for example, to be able to cache the response.
The text was updated successfully, but these errors were encountered: