fix: scheme is case-insensitive.

This commit is contained in:
ajspig 2026-07-21 10:43:00 -04:00
parent f3fb03caf8
commit 895d314b86
1 changed files with 3 additions and 3 deletions

View File

@ -22,13 +22,13 @@ export interface Env {
*/
export function parseConfig(request: Request, env: Env = {}): HonchoConfig {
const authHeader = request.headers.get("Authorization");
const trimmedAuthHeader = authHeader?.trim();
if (!trimmedAuthHeader?.startsWith("Bearer ")) {
const bearerMatch = authHeader?.trim().match(/^Bearer\s+(.*)$/i);
if (!bearerMatch) {
throw new Error(
"Missing Authorization header. Provide 'Authorization: Bearer <your-honcho-key>'.",
);
}
const apiKey = trimmedAuthHeader.substring(7).trim();
const apiKey = bearerMatch[1].trim();
if (!apiKey) {
throw new Error("Authorization header is empty after 'Bearer '.");
}