Open pilcrowonpaper opened 1 year ago
Encountered a similar issue while trying to validate headers using a schema.
headers: t.Object({
"User-Agent": t.String()
})
It triggers a validation error:
$ curl localhost:3000
Invalid headers, 'User-Agent': Expected string
Expected: {
"User-Agent": ""
}
Found: {
"host": "localhost:3000",
"user-agent": "curl/8.0.1",
"accept": "*/*"
}
Simply changing it to lowercase fixes the problem:
headers: t.Object({
"user-agent": t.String()
})
@SaltyAom Perhaps we should use the Fetch API's Headers
interface for this? It handles case-sensitivity automatically. Besides, it's a Web standard which Deno, Bun and Node.js 18 all support.
BTW, one of the reasons I don't use elysia is because it's hard to control the HTTP Headers.
+1 on this
I just got stuck on this as well, especially since typing it with the swagger plugin like this:
works wonders with the swagger UI:
But then you get 422 errors when you're testing the APIs :sweat_smile:
Currently,
Set-Cookie
andset-cookie
are treated as different headers when usingContext.set.headers
even thought headers are case insensitive (RFC 2616).To keep the current API,
set.headers
will need to use setters and getters, so I'd argue implementingcontext.response
solution mentioned in #98 makes more sense here.