fix: read res.headers so content-type params don't break header matchers#892
Open
abhu85 wants to merge 1 commit into
Open
fix: read res.headers so content-type params don't break header matchers#892abhu85 wants to merge 1 commit into
abhu85 wants to merge 1 commit into
Conversation
`_assertHeader` read `res.header[field]`. superagent copies content-type parameters onto the response object, so a value like `text/csv; header=present` overwrites `res.header` with the param value, making every `.expect(field, value)` assertion fail with `expected "<field>" header field`. Read from `res.headers` instead — the untouched header map.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #876.
If a response's
Content-Typecarries aheader=parameter — which is valid fortext/csv(RFC 7111:header=present/header=absent) — every header assertion breaks:Cause
_assertHeaderreads the header fromres.header:superagent's
_setHeaderPropertiescopies every content-type parameter onto the response object (this[key] = parameters[key]). A parameter literally namedheadertherefore overwritesres.header(normally the header map) with the string"a", sores.header[field]isundefinedfor every field.res.headers— the canonical header map — is left untouched.Fix
Read from
res.headersinstead ofres.header:One line;
res.headersis the same map superagent populates and isn't subject to the content-type-parameter clobbering.Test plan
test/issue-fixes.js(Issue [fix] content-type with "header=" breaks all header matchers #876): a route returningContent-Type: text/csv; header=present—.expect('X-Custom', 'value')now passes.master(expected "X-Custom" header field) and passes with the fix.eslintclean.