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

HTTPAltRequestValidator does not retry the original request #27

Closed
haemi opened this issue Mar 18, 2022 · 2 comments
Closed

HTTPAltRequestValidator does not retry the original request #27

haemi opened this issue Mar 18, 2022 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@haemi
Copy link

haemi commented Mar 18, 2022

Thanks for this awesome library, would love to use it in production!

The problem I'm currently facing is that when my original request returns a 401, the HTTPAltRequestValidator works as expected (i.e. it does the login call and sets it on the client), but my original request is not repeated as I see in a proxy running on my mac.

this is my request:

HTTPRequest {
                $0.url = URL(string: "https://...")
                $0.maxRetries = 3
                $0.method = .get
            }

and this is my setup:

        let client = HTTPClient.shared

        let authValidator = HTTPAltRequestValidator(statusCodes: [.unauthorized]) { request, response in
            // If triggered here you'll specify the alt call to execute in order to refresh a JWT session token
            // before any retry of the initial failed request.
            return try! Endpoint.login("...", "...").httpRequest()
        } onReceiveAltResponse: { request, response in
            // Once you have received response from your `refreshToken` call
            // you can do anything you need to use it.
            // In this example we'll set the global client's authorization header.
            if let authorizationHeader = response.headers[.authorization] {
                client.headers.set(.authorization, authorizationHeader)
            }
        }

        client.validators.insert(authValidator, at: 0)

I get to the the client.headers.set(.authorization, authorizationHeader) - but then the original request is not repeated... what am I missing here?

Thanks a lot for your help!

@malcommac malcommac added the bug Something isn't working label Mar 18, 2022
@malcommac malcommac self-assigned this Mar 18, 2022
@malcommac
Copy link
Collaborator

Hi @haemi, you're right, there was a bug with the HTTPAltRequestValidator which can't perform the retry mechanism.

I've solved it in 8bbe0fb while the 45cea68 introduces several unit tests for the validator itself.

I'll release it shortly.

@malcommac malcommac added this to the 1.3.0 milestone Mar 19, 2022
@haemi
Copy link
Author

haemi commented Mar 19, 2022

Hi @malcommac , AWESOME!

With the new branch .package(name: "RealHTTP", url: "https://github.com/immobiliare/RealHTTP.git", branch: "fix/27-alt-validator"), my test just turned green, thanks a lot!

image

malcommac added a commit that referenced this issue Mar 19, 2022
#27 - Fixes for retry mechanism of the HTTPAltRequestValidator
@malcommac malcommac changed the title HTTPAltRequestValidator fetches 401, but original request is not repeated HTTPAltRequestValidator does not retry the original request Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants