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

OnBeforeRequest and default middleware order documentation and code mismatch #686

Closed
leejuyuu opened this issue Aug 11, 2023 · 2 comments · Fixed by #701
Closed

OnBeforeRequest and default middleware order documentation and code mismatch #686

leejuyuu opened this issue Aug 11, 2023 · 2 comments · Fixed by #701

Comments

@leejuyuu
Copy link
Contributor

The documentation of OnBeforeRequest

resty/client.go

Lines 403 to 405 in 3d08b36

// OnBeforeRequest method appends request middleware into the before request chain.
// Its gets applied after default Resty request middlewares and before request
// been sent from Resty to host server.

says that the middleware set by this function is applied after the default middlewares.

However, when the request is executed, the order is reversed.

resty/client.go

Lines 896 to 912 in 3d08b36

// Apply Request middleware
var err error
// user defined on before request methods
// to modify the *resty.Request object
for _, f := range c.udBeforeRequest {
if err = f(c, req); err != nil {
return nil, wrapNoRetryErr(err)
}
}
// resty middlewares
for _, f := range c.beforeRequest {
if err = f(c, req); err != nil {
return nil, wrapNoRetryErr(err)
}
}

I think this resulted in #517.

I am not sure which side is the intended result.

@jeevatkm
Copy link
Member

@leejuyuu Thanks for bringing it up. I didn't notice it. The documentation needs correction. I will correct it, or you could submit the PR. Please let me know.

As @0140454 mentioned in the #517 (comment), this is the correct order of execution.

leejuyuu added a commit to leejuyuu/resty that referenced this issue Sep 23, 2023
The documentation about the order of middleware application
for OnBeforeRequet was different from the implementation. Fixed this by
changing the documentation.

Fixes go-resty#686.
@leejuyuu
Copy link
Contributor Author

@jeevatkm Thanks for the reply! Opened #701.

jeevatkm pushed a commit that referenced this issue Sep 23, 2023
The documentation about the order of middleware application
for OnBeforeRequet was different from the implementation. Fixed this by
changing the documentation.

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

Successfully merging a pull request may close this issue.

2 participants