Skip to content
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

[REQ] support follow redirects in swift libraries #13597

Closed
Jonas1893 opened this issue Oct 5, 2022 · 1 comment
Closed

[REQ] support follow redirects in swift libraries #13597

Jonas1893 opened this issue Oct 5, 2022 · 1 comment

Comments

@Jonas1893
Copy link
Contributor

Is your feature request related to a problem? Please describe.

We have an API that uses ETags to implement a simple caching mechanism for large image data. We are requesting with the ETag of the locally cached image data in the request header and a response is either

  • 302 with a Location redirect header redirecting the client to the blob storage with an updated ETag in the response header
  • or 304 not modified, indicating that the locally cached data in the client (as indicated by the ETag) is not outdated and can still be used.

Currently two things are preventing this to work with the generator:

  1. The generated APIs for responses that define redirects will currently be generated with a Void return type. Both URLSession and Alamofire libraries currently already follow the redirect URL from the location header, however the data that is being retrieved is being discarded by always mapping to Void.
  2. Successful status code range is currently hardcoded for both URLSession and Alamofire implementations to 200..< 300. both 302 and 304 are treated as failure and the image data can not be returned to the caller

Describe the solution you'd like

For solving problem 1. I propose to change the return type to Data for redirect responses and pass the returned Data. This should probably sit behind a new generator flag to stay backwards compatible.
For solving problem 2. I propose to add the configuration option for changing the successful status code range. This can also be useful for other use cases beyond the scope of follow redirects, that's I would propose to add this in a separate PR

Describe alternatives you've considered

I don't think there are many other options currently other than changing the API spec and directly returning image data instead of sending Location redirects headers. However for our project this is not possible

Additional context

Bildschirmfoto 2022-10-05 um 08 18 10

@Jonas1893 Jonas1893 changed the title [REQ] support follow redirects in swift5 libraries [REQ] support follow redirects in swift libraries Oct 18, 2022
@Jonas1893
Copy link
Contributor Author

Returned bodyData from redirect is now passed through Response object that can be accessed for each API. APIs that rely on follow redirects are now properly supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant