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

dont serialize null as header values #250

Merged
merged 1 commit into from Jun 24, 2023

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jun 24, 2023

fixes #249

Checklist

Copy link
Member

@Fdawgs Fdawgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got me as I use undefined in my header tests, thanks for the fix!

@Fdawgs Fdawgs merged commit 97a9c12 into master Jun 24, 2023
15 checks passed
@Fdawgs Fdawgs deleted the dont-serialize-null-header-value branch June 24, 2023 14:54
@mcollina
Copy link
Member

Technically this does not match node core behavior. It serializes null as 'null', and this module mimics core as much as possible.

@Fdawgs
Copy link
Member

Fdawgs commented Jun 24, 2023

Technically this does not match node core behavior. It serializes null as 'null', and this module mimics core as much as possible.

Ah balls, what about undefined?

@Fdawgs
Copy link
Member

Fdawgs commented Jun 25, 2023

Technically this does not match node core behavior. It serializes null as 'null', and this module mimics core as much as possible.

Ah balls, what about undefined?

@mcollina @Uzlopak thoughts on this?

@mcollina
Copy link
Member

const { createServer, request } = require('http');

const server = createServer((req, res) => {
  res.setHeader('Content-Type', 'text/plain');

  try {
    res.setHeader('X-undefined', undefined);
  } catch (err) {
    console.log('undefined could not be set')
  }
  res.setHeader('X-null', null);
  res.end('Hello World!');
})

server.listen(3000, function () {
  console.log('Server listening on port 3000');
  request('http://localhost:3000', function (res) {
    console.log(res.headers);
    process.exit(0);
  }).end()
});

mcollina added a commit that referenced this pull request Jun 25, 2023
@Fdawgs
Copy link
Member

Fdawgs commented Jun 25, 2023

Aight, cool.

I was using undefined in my tests like so to remove expected headers that I... no longer expected:

const sitewideExpectedHeaders = {
	  'Content-Type': 'application/json',
	  expires: "0",
}

const cacheablepageExpectedHeaders = {
	...sitewideExpectedHeaders,
	expires: undefined
}

Guess I'll need to just change it to use delete cacheablepageExpectedHeaders.expires instead.

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

Successfully merging this pull request may close these issues.

Headers with value set to null are wrongly emitted as string in the response
4 participants