Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in Documentation Regarding Accessing Header from headers Context #274

Open
InfoDevkota opened this issue Feb 25, 2024 · 0 comments

Comments

@InfoDevkota
Copy link
Contributor

What is the type of issue?

No response

What is the issue?

new Elysia()
    .derive(({ headers }) => {
        const auth = headers['Authorization']
        ....

Headers are case insensetive while accessing directly from request. request.headers.get('Authorization') and request.headers.get('AUTHorization') gives the result. But with the headers context and accessing the Header with bracket notation, the case matters. In the headers context, all the headers are saved on lower case. thus we need to use headers['authorization'] and same for other and custom headers.

We need to fix the snippet, and need to mention about it on the Documentation as well.

Where did you find it?

While going from top in the documentation.

Encountered on Essential -> Context -> Derive.

import { Elysia } from 'elysia'

new Elysia()
    .derive(({ headers }) => {
        const auth = headers['Authorization']
       // HERE
       // const auth = headers['authorization']

        return {
            bearer: auth?.startsWith('Bearer ') ? auth.slice(7) : null
        }
    })
    .get('/', ({ bearer }) => bearer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant