-
Notifications
You must be signed in to change notification settings - Fork 723
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
Possible Authorization header bug in v2.16.4 #959
Comments
@danversjflett Thanks for reaching out. I'm unable to reproduce it, can you double check and share feedback? package main
import (
"fmt"
"github.com/go-resty/resty/v2"
)
func main() {
c := resty.New()
res, err := c.R().
SetBody(map[string]string{
"name": "Resty",
}).
SetAuthScheme("Bearer"). // FYI, this is default value
SetAuthToken("token-here").
Post("https://httpbin.org/post")
fmt.Println(err, res)
} Output:
|
@jeevatkm Thanks for looking at this. In the example code you give, the Authorization token is added unconditionally. In our code, the authorization token is added with a Retry Hook. This code is closer to how we use Resty:
I can't use this example to exactly demonstrate the issue because httpbin doesn't give us a |
@jeevatkm I've found a way to recreate this, by getting httpbin to randomly return a 200 or 401 status code:
Output with Resty v2.16.3:
Output with Resty v2.16.4:
Note that the outward behavior is the same but the request header in v2.16.4 has no Authorization header. |
@danversjflett Thanks for your code snippet. I found the root cause. It seems your implementation uses only client-level methods, not request-level like my example above. With this recent 4eae633 commit, this is the side effect of it. Technically, the following line could solve your issue -
However, library behavior should not change in the patch version. I will fix it. |
@danversjflett Can you try this branch |
@danversjflett, did you get a chance to validate it? |
@jeevatkm I just tested it with the example code and in our production code and the problem appears to be fixed. Thank you. |
@danversjflett Thanks for the confirmation. |
Hi. I've just updated Resty in my project to v2.16.4.
We use bearer token authorization headers in our project.
We set up the Resty client using:
SetAuthScheme("Bearer").SetAuthToken(token)
This has worked for us up to v2.16.3.
Now we are getting Status Code 401 Unauthorized from the API. I can set a breakpoint and debug the code after the response is received - I see that the Resty client has the "Token" field set to the token we give it, but in the request the "Authorization" Header is not set at all.
In previous versions, the "Authorization" Header in a request made by the client is set to "Bearer [token]".
The text was updated successfully, but these errors were encountered: