Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.
This repository was archived by the owner on May 3, 2024. It is now read-only.

Setting headers on ctx.request in middleware (request proxy bug?) #7

@ptim

Description

@ptim

Hi! Thanks for your work on Sunder - loving it, learning plenty 🙏

I'm not sure if this issue is a bug, or user error…

I'm trying to add headers on the request object so that I can tweak the behaviour of sub-fetches (for caching and image resizing, etc).

I see that HeadersShorthands makes provision for this, but what I'm seeing is:

// in my middleware...
ctx.request['x-foo-header'] = 'bar
console.log(request['x-foo-header']) // 'bar'
console.log(request.headers.get('x-foo-header')) // null

request.headers.set('x-foo-header', 'bar')
// TypeError: immutable
//      at Headers.set ([/project/node_modules/undici/lib/fetch/headers.js:293:13]())

I'm expecting that:

  • ctx.request['x-foo-header'] will be handled by the get trap on Sunder's proxied request, and return ctx.request.headers.get('x-foo-header')
  • ctx.request['x-foo-header'] = 'bar' would similarly trigger the set trap and mutate request.headers

So I guess there are two issues here:

  • am I using the proxy correctly?
  • do the HeadersShorthands work as expected? I figure if the set trap was getting hit as expected, then I'd see a type error (I didn't find any relevant tests)

Regards, Tim

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions