-
Notifications
You must be signed in to change notification settings - Fork 405
feat: Make 429 passthrough instead return 401 #1232
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,6 +204,20 @@ func forwardRequestToSessionStore(client *http.Client, r *http.Request, cf Authe | |
| return json.RawMessage{}, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("Unable to fetch cookie session context from remote: %+v", err)) | ||
| } | ||
| return body, nil | ||
| } else if res.StatusCode == http.StatusTooManyRequests { | ||
| // Handle rate limiting - pass through the response | ||
| body, _ := io.ReadAll(res.Body) | ||
| err := helper.ErrTooManyRequests | ||
| if len(body) > 0 { | ||
| err = err.WithReasonf("%s", string(body)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body may be some HTML, do we really want it in the error as JSON? It will look super strange
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @aeneasr, I agree, embedding the raw body isn't ideal, i was just focus on my use case. What's your preference here:
Let me know what you think would work best!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we should remove this body inclusion and move the x- headers to the response body |
||
| } | ||
| // Pass through important rate limit headers | ||
| for _, header := range []string{"Retry-After", "X-RateLimit-Limit", "X-RateLimit-Remaining", "X-RateLimit-Reset", "X-RateLimit-Type"} { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think oathkeeper should return these as header |
||
| if value := res.Header.Get(header); value != "" { | ||
| err = err.WithDetail(header, value) | ||
| } | ||
| } | ||
| return json.RawMessage{}, errors.WithStack(err) | ||
| } else { | ||
| return json.RawMessage{}, errors.WithStack(helper.ErrUnauthorized) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be possible to pass through these headers and the body? Also what about the other handlers with upstream code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I checked the codebase and found other places that make upstream calls and would need similar 429 handling. As i said before, i was concentrated on my use case. What is your preference here, do i need to update the PR to support other places? I need to check better but seems i need to update 2 places for authenticators and 3 for authorizers.
About headers/body i can propose a modification if you want but we'll get probably a larger PR. So we have 2 options i think for this PR. 1. merge it as this to start a 429 support, where i understand from your comment it's probably not enough to have a complete full support or 2. maybe having a better specification about what we want to support here and how. I think you the best person to make this choice :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the other places, i did a new commit, let me know if it what you have in your mind for the other handlers.