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

All response headers are converted to string #118

Closed
pheekus opened this issue Jul 17, 2023 · 4 comments · Fixed by #119
Closed

All response headers are converted to string #118

pheekus opened this issue Jul 17, 2023 · 4 comments · Fixed by #119
Labels
bug Something isn't working

Comments

@pheekus
Copy link

pheekus commented Jul 17, 2023

This seems to be intentional but it breaks compatibility with packages like node-oidc-provider that expect response.getHeader() to return the same data type as was passed to response.setHeader(), which is what the node docs say should happen.

For context, here's what happens in one of the projects I'm working on for a client. We're using nuxt3 deployed with the aws-lambda nitro preset. Several API routes pass ServerResponse instances from this framework to node-oidc-provider that sets multi-value set-cookie header in one module and reads it afterwards in another one. Since the original value is an array, it expects to receive an array back. Instead of that, it gets a comma-separated string and errors.

Relevant code is below. If this is the behaviour you're planning to keep, I'd appreciate a quick comment about that so I and everyone else who stumbles upon this issue can look into a workaround. Thanks :)

this._headers[name.toLowerCase()] = value + "";

@Hebilicious
Copy link
Member

Hi, can you provide a small reproduction please ?
I would like to know if you're doing all of this in an event handler and which methods you're using exactly.

@pheekus
Copy link
Author

pheekus commented Jul 19, 2023

@Hebilicious sure thing, I'll get you a test project to look at by the end of this week

@pheekus
Copy link
Author

pheekus commented Jul 19, 2023

@Hebilicious here's the repo, it's a heavily simplified version of the project I'm working on. I've included some comments on what it is and how it works in the readme: unjs-unenv-issue-118-demo.

@pheekus
Copy link
Author

pheekus commented Jul 19, 2023

This is a bit off-topic/cross-project BUT if anyone else experiences similar issues with headers/cookies/base64 in a nuxt3 app built with the aws-labmda preset, a custom preset with serverless-http worked super well for me as a temporary solution:

preset/entry.ts:

import "#internal/nitro/virtual/polyfill";
import { toNodeListener } from "h3";
import serverless from "serverless-http";

const listener = toNodeListener(useNitroApp().h3App);
export const handler = serverless(listener, { provider: "aws" });

preset/nitro.config.ts:

import type { NitroPreset } from "nitropack";
import { fileURLToPath } from "node:url";

export default <NitroPreset>{
  extends: "node-server",
  entry: fileURLToPath(new URL("./entry.ts", import.meta.url)),
};

nuxt.config.ts:

nitro: {
  preset: "./preset",
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants