question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when using HTTP2

See original GitHub issue

apollo-server doesn’t seem to like when Node’s http2 module is used. When an HTTP2 client (i.e. the browser) makes a request, this error happens:

TypeError: :method is not a legal HTTP header name

  - index.js:670 validateName
    [venom-api]/[apollo-server-env]/[node-fetch]/lib/index.js:670:9

  - index.js:830 Headers.append
    [venom-api]/[apollo-server-env]/[node-fetch]/lib/index.js:830:3

  - nodeHttpToRequest.ts:11 Object.keys.forEach.key
    [venom-api]/[apollo-server-core]/src/nodeHttpToRequest.ts:11:15

  - Array.forEach

  - nodeHttpToRequest.ts:6 Object.convertNodeHttpToRequest
    [venom-api]/[apollo-server-core]/src/nodeHttpToRequest.ts:6:28

...more stuff

Since apollo-server-core uses Request and Headers objects from node-fetch, I’m not sure whether this is an upstream problem or not. The problem is that node-fetch doesn’t seem to support the “special” header names documented here.

In HTTP/2, the request path, hostname, protocol, and method are represented as special headers prefixed with the : character (e.g. ‘:path’). These special headers will be included in the request.headers object.

Since nodeHttpToRequest isn’t actually using node-fetch to make an HTTP request, this seems to me like a problem internal to Apollo Server. node-fetch has their own issue here for HTTP2, but that seems to be concerned with making HTTP2 requests.

Reproduction:

(I use Koa)

const Koa = require('koa');
const { ApolloServer } = require('apollo-server-koa');
const http2 = require('http2');

const app = new Koa();
const apollo = new ApolloServer({ etc });
apollo.applyMiddleware(app);
const server = http2.createSecureServer({ cert: 'cert here', key: 'key here' }, app.callback());
server.listen(8000);

Then make a GraphQL request, with your browser, to https://localhost:8000/ (browsers do not allow insecure HTTP2, so you’ll have to ignore the security warning)

Potential Fix

In nodeHttpToRequest, ignore headers starting with :

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:39
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
theJCcommented, Jan 28, 2021

Has any progress been made on this front, or any additional plans formed?

8reactions
selipsocommented, Oct 17, 2018

Also interested in having HTTP2 work with Apollo. Since Express doesn’t support HTTP2 natively yet, it may be worth creating a wrapper for spdy with an HTTP2 boolean flag that can be passed in when calling / creating a new ApolloServer

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is ERR_HTTP2_PROTOCOL_ERROR? How to Fix it?
HTTP2 protocol error might occur on a client device mainly due to browser issues or interference from the network.
Read more >
What's the net::ERR_HTTP2_PROTOCOL_ERROR about?
The issue is that when there's no disk space left on the disk, some webservers (nginx definitely but maybe apache as well) are...
Read more >
How to Fix ERR_HTTP2_PROTOCOL_ERROR in Chrome
The ERR_HTTP2_PROTOCOL_ERROR in Google Chrome can occur due to the browser and network issues and interference from third-party software. This ...
Read more >
How to Fix the err_http2_protocol_error
1. Refresh the webpage. · 2. Try using a different browser. · 3. Download and install any browser updates. · 4. Clear your...
Read more >
Err_http2_protocol_error? Please help, all browsers including ...
Other people in my house using the same Internet have no issue browsing on chrome. I've connected to a wireless hot-spot but the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found