elysiajs / eden

Fully type-safe Elysia client
MIT License
147 stars 37 forks source link

Can't use Uppercase headers #102

Open mrctrifork opened 3 months ago

mrctrifork commented 3 months ago

Eden lowercases headers right before sending them over the wire.

This is apparently fine due to HTTP 1.1 says header names ought to be case insensitive.

The problem comes when you define a schema for your headers in Elysia. Let's assume the following example:

export const app = new Elysia()
.get(
        '/headers-uppercased',
        ({ headers, headers: { username, alias } }) => ({
            username,
            alias,
            authorization: headers.Authorization
        }),
        {
            headers: t.Object({
                username: t.String(),
                alias: t.Literal('Kristen'),
                Authorization: t.Optional(t.Literal('Bearer token'))
            })
        }
    )

This example fails as, of course, Eden will lowercase the Authorization header and therefore the schema validator will expect an Uppercased Authorization header.