Skip to content

Loading…

Missing header returns undefined as typeof string #1152

Closed
Tivoli opened this Issue · 5 comments

4 participants

@Tivoli

express v3.0.0alpha4

In a route using req.get(field) if the field doesn't exist it will return the string 'undefined' instead of undefined.

@tj tj closed this in 685eec0
@tj
tj commented

looks fine to me

@Tivoli

req.get('Something-Else') does work correctly, I narrowed it down, req.get('X-AppID') fails, any other X-* header field works correctly as does any other header field name I've tested.

@chjj

Completely unrelated: What's up tivs?!

-Stuck

@Tivoli

Actually never mind, it was an error on my side, sorry for the false report.

@eschwartz

Here's what I ran into:

res.set({
  'Expires': getExpires(),
});

res.get('Expires')  // "undefined"

function getExpires() {
  // ...failed to get an expires time...
  return undefined;
}

When you set a header value of undefined, it looks like Express casts it to the string "undefined". This kind of feels like funky behavior on the part of Express -- I might expect that setting a header value of undefined would just not set that header.

Anyways, hope this helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.