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

Handling multiple RateLimit-Policy and RateLimit headers #137

Open
kevinswiber opened this issue Oct 30, 2024 · 5 comments
Open

Handling multiple RateLimit-Policy and RateLimit headers #137

kevinswiber opened this issue Oct 30, 2024 · 5 comments

Comments

@kevinswiber
Copy link

There's support for multiple policies in a single RateLimit-Policy header, but how should clients process multiple RateLimit-Policy headers? And what happens if a single response has multiple RateLimit headers?

@darrelmiller
Copy link
Contributor

Clients can track remaining quota for each policy using the policy identifier as key. When the client receives a RateLimit header they policy identifier is used to track which is the associated policy.

GET /foo

200 OK
RateLimit-Policy: policy1;q=100;w=3600, policy2;q=1000;w=36400;
RateLimit: policy1;r=20;t=20, policy2;r=121;t=300;

@nfriedly
Copy link

nfriedly commented Nov 7, 2024

Just to double-check, is

GET /foo

200 OK
RateLimit-Policy: policy1;q=100;w=3600, policy2;q=1000;w=36400;
RateLimit: policy1;r=20;t=20, policy2;r=121;t=300;

considered functionally equivalent to

GET /foo

200 OK
RateLimit-Policy: policy1;q=100;w=3600;
RateLimit: policy1;r=20;t=20;
RateLimit-Policy: policy2;q=1000;w=36400;
RateLimit: policy2;r=121;t=300;

Or is there a requirement that they're combined into a single RateLimit-Policy header and a single RateLimit header?

(I'd prefer treating the two as functionally equivalent, and I think some systems will automatically transform the later into the former.)

@Acconut
Copy link

Acconut commented Nov 7, 2024

Yes, they are equivalent. Since RateLimit and RateLimit-Policy are Lists from Structured Fields, their entries can be split across fields or combined. See https://www.rfc-editor.org/rfc/rfc8941#name-lists for details and an example.

@kevinswiber
Copy link
Author

kevinswiber commented Nov 7, 2024

@darrelmiller @Acconut Oh, I completely missed this section!

This document uses the terms List, Item and Integer from Section 3 of [STRUCTURED-FIELDS] to specify syntax and parsing, along with the concept of "bare item".

I wonder if there's a way to make this clearer in the spec. Not only did I not see this, but I didn't register why "List" was capitalized in this paragraph:

The "RateLimit-Policy" response header field is a non-empty List of Quota Policy Items (Section 3.1).

Even if we repeat that it's a Structured Field here, I think the repetition would be worth it.

Thanks for clarifying!

@Acconut
Copy link

Acconut commented Nov 11, 2024

Thanks for the feedback. I'm not an editor on this draft, but I would support adding a sentence that mentions that RateLimit and RateLimit-Policy header fields can be split and merged due to them being SF Lists.

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

No branches or pull requests

4 participants