ietf-wg-httpapi / ratelimit-headers

Repository for IETF WG draft ratelimit-headers
Other
42 stars 4 forks source link

How can a client correlate a service limit with the corresponding policy? #121

Closed darrelmiller closed 1 year ago

darrelmiller commented 1 year ago

If server defines two policies, e.g.

RateLimit-Policy:  100; w=10; unit=requests, 100; w=10; unit=bytes

and the response header contains,

RateLimit-Limit:  100
RateLimit-Remaining:  2
RateLimit-Reset:  60

How do I know if I can make 2 more requests, or download 2 more bytes?

Is having multiple policies with different quota units not allowed?

ioggstream commented 1 year ago

Good catch! The list items MUST be unique. I will specify this for now.

WDYT about switching Policy to a Dictionary? This requires some tweak though e.g. prefixing the units with u.

from http_sfv import Dictionary
# RateLimit-Limit: 100
# RateLimit-Policy: u100=10; unit="requests"
limit = Item()
limit.parse(b'100')
policies = Dictionary()
policies.parse(b'u100=10; unit="requests", u1000=200; unit="requests"')
policy = policies[f'u{limit.value}]

cc: @mnot

mnot commented 1 year ago

I'd use a short name for the policy, so that it could be referred to separately; e.g.,

RateLimit-Policy: shortreqlimit; unit=requests; limit=100; window=10  
RateLimit: shortreqlimit; remaining=15; reset=5