Skip to content

fix(response): preserve user-supplied content-type parameters on send - #2022

Open
CloudCorpRecords wants to merge 1 commit into
restify:masterfrom
CloudCorpRecords:fix-content-type-params
Open

CloudCorpRecords wants to merge 1 commit into
restify:masterfrom
CloudCorpRecords:fix-content-type-params

Conversation

@CloudCorpRecords

Copy link
Copy Markdown

Pre-Submission Checklist

  • Opened an issue discussing these changes before opening the PR (Additional content-type parameters are thrown away #1589, where the agreed direction was to keep the user-provided content type)
  • Ran the linter and tests via make prepush (eslint clean; 902 nodeunit assertions and 217 mocha plugin tests pass)
  • Included comprehensive and convincing tests for changes

Issues

Closes:

Changes

res.send() split the content type on ; to derive the base type for formatter lookup, but then reused that stripped value for the outgoing Content-Type header. So res.contentType = 'text/plain; version=0.0.4; charset=utf-8' went out as plain text/plain, silently dropping parameters like the Prometheus exposition version.

The fix keeps the parameters aside before formatter lookup and restores them on the header that is actually sent. The base type is still what drives formatter selection, and res.charSet() behavior is unchanged (its charset is appended as before, with no duplication of user params).

Tests added in test/response.test.js:

Signed-off-by: Rene Turcios 95189389+CloudCorpRecords@users.noreply.github.com

res.contentType = 'text/plain; version=0.0.4' was stripped to 'text/plain'
because send() split the type on ';' for formatter lookup and then used the
stripped value for the outgoing Content-Type header. Keep the parameters
aside for lookup, then restore them on the header. res.charSet() behavior
is unchanged.

Fixes restify#1589.

Signed-off-by: Rene Turcios <95189389+CloudCorpRecords@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

1 participant