restify / restify/node-restify

Additional content-type parameters are thrown away

Open
#1,589 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Critical Good First Issue Help Wanted Needs Discussion
Dominant language
JavaScript
Stars
10.7k
Forks
975
Avg merge
1d 6h
Merged PRs (30d)
5

Description

  • Used appropriate template for the issue type
  • Searched both open and closed issues for duplicates of this issue
  • Title adequately and concisely reflects the feature or the bug

Bug Report

Restify Version

6.3.4

Node.js Version

8.9.1

Expected behaviour

Given the following code, I would expect the content-type string I set to be used.

res.contentType = "text/plain; version=0.0.4; charset=utf-8"
res.send(...)

Should produce:

Content-Type: text/plain; version=0.0.4; charset=utf-8

For context, the content-type I'm using comes from: Prometheus client, Prometheus docs

Actual behaviour

Only the contents of the string before the first ; are used, resulting in:

Content-Type: text/plain

Repro case

var restify = require('restify');

const server = restify.createServer({
  name: 'myapp',
  version: '1.0.0'
});

server.get('/test', function (req, res, next) {
  res.contentType = "text/plain; version=0.0.4; charset=utf-8"
  res.send(200, "some text")
  return next();
});

server.listen(8080, function () {
  console.log('%s listening at %s', server.name, server.url);
});

Cause

The string is split here, throwing away the rest:

https://github.com/restify/node-restify/blob/74e0cf55fc452931215280741516d30555d76f7a/lib/response.js#L466

Are you willing and able to fix this?

Maybe 😄

Assuming there isn't some reason this is intended behaviour, I can have a look at fixing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/response.js at the content-type handling around line 466 and run the provided Restify reproduction. Preserve the complete content-type value, including parameters, and verify that the response emits text/plain; version=0.0.4; charset=utf-8 rather than only text/plain.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.