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

ServerResponse#appendHeader not implemented #19993

Closed
cyco130 opened this issue Jul 31, 2023 · 4 comments · Fixed by #24216
Closed

ServerResponse#appendHeader not implemented #19993

cyco130 opened this issue Jul 31, 2023 · 4 comments · Fixed by #24216
Assignees
Labels
bug Something isn't working correctly node API polyfill Related to various "node:*" modules APIs node compat

Comments

@cyco130
Copy link

cyco130 commented Jul 31, 2023

The appendHeader method of ServerResponse from the node:http module doesn't seem to have been implemented. This makes it impossible to return multiple Set-Cookie headers from the server when using node:http (I tried a few other ways like passing an array to setHeader or calling writeHead with an array value for set-cookie but none seemed to work).

System Info

Deno version: 1.35.3
OS: macOS 13.4.1
CPU: (10) arm64 Apple M1 Max
@bartlomieju bartlomieju added bug Something isn't working correctly node compat labels Jul 31, 2023
@cyco130
Copy link
Author

cyco130 commented Jul 31, 2023

Temporary workaround (forces Headers#set to accept an array, probably not standards-compliant):

const oldSet = Headers.prototype.set;
Headers.prototype.set = function set(
  this: Headers,
  key: string,
  value: string | string[]
) {
  if (Array.isArray(value)) {
    this.delete(key);
    value.forEach((v) => this.append(key, v));
  } else {
    oldSet.call(this, key, value);
  }
};

@bartlomieju
Copy link
Member

@cyco130 do you have some reproduction code? We have this method implemented here:

appendHeader(name, value) {

@cyco130
Copy link
Author

cyco130 commented Jul 31, 2023

The problem is that ServerResponse doesn't extend OutgoingMessage as it does on Node (it extends Writable instead).

Reproduction is simply:

import { ServerResponse } from "node:http";
console.assert(typeof new ServerResponse({}).appendHeader === "function");

@bartlomieju
Copy link
Member

Ah, good catch! Thanks for pointing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node API polyfill Related to various "node:*" modules APIs node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants