restify / restify/node-restify

TypeError: Invalid value "null" for header "content-type" (lib/plugins/static.js)

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

Nobody has claimed this yet.

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

8.2.0

Node.js Version

10.15.3

Expected behaviour

I can serve static files over HTTP/2 without errors

Actual behaviour

internal/http2/compat.js:66
throw err;
^

TypeError [ERR_HTTP2_INVALID_HEADER_VALUE]: Invalid value "null" for header "content-type"
at Http2ServerResponse.[setHeader] (internal/http2/compat.js:543:5)
at Http2ServerResponse.setHeader (internal/http2/compat.js:538:21)
at Http2ServerResponse.header (/app/node_modules/restify/lib/response.js:226:14)
at Http2ServerResponse.set (/app/node_modules/restify/lib/response.js:548:18)
at ReadStream.onceOpen (/app/node_modules/restify/lib/plugins/static.js:118:17)
at Object.onceWrapper (events.js:277:13)
at ReadStream.emit (events.js:189:13)
at ReadStream.EventEmitter.emit (domain.js:441:20)
at lazyFs.open (internal/fs/streams.js:120:10)
at FSReqWrap.args [as oncomplete] (fs.js:140:20)

Repro case

import Restify from 'restify';
import { readFileSync } from 'fs';

const cert = readFileSync(...);
const key = readFileSync(...);
const server = Restify.createServer({ http2: { cert, key, allowHTTP1: false } });
server.get('/*', Restify.plugins.serveStatic({
    directory: path.join(__dirname, '../static'),
    default: 'index.html'
  }));
server.listen(443);

Then you make a HTTP request for a CUR file (for example):

GET https://localhost/images/openhand.cur

Cause

/lib/plugins/static.js:118:17

mime.getType() returns null, which is not accepted by Http2ServerResponse.setHeader

Are you willing and able to fix this?

Yes, I have a fix and can make a Pull Request:

https://github.com/drash-course/node-restify/tree/content-type-patch

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

Review lib/plugins/static.js at line 118, where mime.getType() supplies the content-type for a served static file. Reproduce the HTTP/2 request for a CUR file, then verify that serving files with an unknown MIME type no longer passes null to the response header.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.