detached 5be4eff

fix(rate-limiter): show correct rate limit points in debug output

commit
5be4effdfa9f1a1480736a3d0e2e77dd61f53041
author
bnema · · 2026-01-18 16:38 UTC
parent
fb2f48e
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +17 -6
M src/lib/api/rate-limiter.ts +17 -6
@@ -71,6 +71,18 @@ function getEndpointType(pathname: string, isPublic: boolean): keyof typeof RATE
7171 return 'protected';
7272 }
7373
74+function getRateLimitPoints(
75+ endpointType: keyof typeof RATE_LIMITS,
76+ isAuthenticated: boolean
77+): number {
78+ if (endpointType === 'sse') {
79+ return isAuthenticated
80+ ? RATE_LIMITS.sse.authenticated.points
81+ : RATE_LIMITS.sse.unauthenticated.points;
82+ }
83+ return RATE_LIMITS[endpointType].points;
84+}
85+
7486 function isRateLimited(
7587 ip: string,
7688 endpointType: keyof typeof RATE_LIMITS,
@@ -176,9 +188,7 @@ export async function handleRateLimit(event: RequestEvent): Promise<Response | n
176188 hasUser: Boolean(event.locals.user),
177189 hasSession: Boolean(event.locals.session),
178190 endpointType,
179- rateLimitPoints: isAuthenticated
180- ? RATE_LIMITS.sse.authenticated.points
181- : RATE_LIMITS.sse.unauthenticated.points
191+ rateLimitPoints: getRateLimitPoints(endpointType, isAuthenticated)
182192 };
183193 }
184194
@@ -193,9 +203,10 @@ export async function handleRateLimit(event: RequestEvent): Promise<Response | n
193203 headers['X-Debug-Has-User'] = Boolean(event.locals.user).toString();
194204 headers['X-Debug-Has-Session'] = Boolean(event.locals.session).toString();
195205 headers['X-Debug-Endpoint-Type'] = endpointType;
196- headers['X-Debug-Rate-Limit-Points'] = isAuthenticated
197- ? RATE_LIMITS.sse.authenticated.points.toString()
198- : RATE_LIMITS.sse.unauthenticated.points.toString();
206+ headers['X-Debug-Rate-Limit-Points'] = getRateLimitPoints(
207+ endpointType,
208+ isAuthenticated
209+ ).toString();
199210 }
200211
201212 return new Response(JSON.stringify(responseBody), {
@@ -71,6 +71,18 @@ function getEndpointType(pathname: string, isPublic: boolean): keyof typeof RATE
71 return 'protected';71 return 'protected';
72 }72 }
73 73
74+function getRateLimitPoints(
75+ endpointType: keyof typeof RATE_LIMITS,
76+ isAuthenticated: boolean
77+): number {
78+ if (endpointType === 'sse') {
79+ return isAuthenticated
80+ ? RATE_LIMITS.sse.authenticated.points
81+ : RATE_LIMITS.sse.unauthenticated.points;
82+ }
83+ return RATE_LIMITS[endpointType].points;
84+}
85+
74 function isRateLimited(86 function isRateLimited(
75 ip: string,87 ip: string,
76 endpointType: keyof typeof RATE_LIMITS,88 endpointType: keyof typeof RATE_LIMITS,
@@ -176,9 +188,7 @@ export async function handleRateLimit(event: RequestEvent): Promise<Response | n
176 hasUser: Boolean(event.locals.user),188 hasUser: Boolean(event.locals.user),
177 hasSession: Boolean(event.locals.session),189 hasSession: Boolean(event.locals.session),
178 endpointType,190 endpointType,
179- rateLimitPoints: isAuthenticated191+ rateLimitPoints: getRateLimitPoints(endpointType, isAuthenticated)
180- ? RATE_LIMITS.sse.authenticated.points
181- : RATE_LIMITS.sse.unauthenticated.points
182 };192 };
183 }193 }
184 194
@@ -193,9 +203,10 @@ export async function handleRateLimit(event: RequestEvent): Promise<Response | n
193 headers['X-Debug-Has-User'] = Boolean(event.locals.user).toString();203 headers['X-Debug-Has-User'] = Boolean(event.locals.user).toString();
194 headers['X-Debug-Has-Session'] = Boolean(event.locals.session).toString();204 headers['X-Debug-Has-Session'] = Boolean(event.locals.session).toString();
195 headers['X-Debug-Endpoint-Type'] = endpointType;205 headers['X-Debug-Endpoint-Type'] = endpointType;
196- headers['X-Debug-Rate-Limit-Points'] = isAuthenticated206+ headers['X-Debug-Rate-Limit-Points'] = getRateLimitPoints(
197- ? RATE_LIMITS.sse.authenticated.points.toString()207+ endpointType,
198- : RATE_LIMITS.sse.unauthenticated.points.toString();208+ isAuthenticated
209+ ).toString();
199 }210 }
200 211
201 return new Response(JSON.stringify(responseBody), {212 return new Response(JSON.stringify(responseBody), {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 8

↑↓ moveenter openesc close