Node: HTTP2 writehead header format can't use array of arrays for headers

Created on 18 Nov 2018  路  4Comments  路  Source: nodejs/node

node 10.13
CentOs
HTTP2

With http, you can send headers like this:
[
[
"Content-Type",
"text/html; charset=utf-8"
],
[
"last-modified",
"Sun, 18 Nov 2018 17:49:47 GMT"
]
]

To send multiple values for the same header, like cookies. But with http2 the returned headers looks like this when this format is used:
https://i.imgur.com/QXZnu4v.png

confirmed-bug http2

Most helpful comment

Unfortunately, we probably should support it.

All 4 comments

@nodejs/http2

I can confirm this diverging behaviour. However the documentation for http.writeHead does not describe the Array of Arrays use case. Should this be supported?

const http = require('http')
const http2 = require('http2')

const headers = [
  [ 'Content-Type', 'text/html; charset=utf-8' ],
  [ 'last-modified', 'Sun, 18 Nov 2018 17:49:47 GMT' ]
]

http.createServer((request, response) => {
  console.log(`Request via HTTP/${request.httpVersion}`)
  response.writeHead(200, headers)
  response.end()
}).listen(8001)

http2.createServer((request, response) => {
  console.log(`Request via HTTP/${request.httpVersion}`)
  response.writeHead(200, headers)
  response.end()
}).listen(8002)
$ curl -v http://localhost:8001
* Rebuilt URL to: http://localhost:8001/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8001 (#0)
> GET / HTTP/1.1
> Host: localhost:8001
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
< last-modified: Sun, 18 Nov 2018 17:49:47 GMT
< Date: Mon, 26 Nov 2018 02:44:23 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
< 
* Connection #0 to host localhost left intact

$ curl -v --http2-prior-knowledge http://localhost:8002
* Rebuilt URL to: http://localhost:8002/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8002 (#0)
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7f8f85000400)
> GET / HTTP/2
> Host: localhost:8002
> User-Agent: curl/7.54.0
> Accept: */*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200 
< 0: Content-Type
< 0: text/html; charset=utf-8
< 1: last-modified
< 1: Sun, 18 Nov 2018 17:49:47 GMT
< date: Mon, 26 Nov 2018 02:32:38 GMT
< 
* Connection #0 to host localhost left intact

Unfortunately, we probably should support it.

A suggestion: deprecate the nested array format starting off node 11after implementing parity. You can already achieve the same functionality trough the documented means, which is what I did.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielstaleiny picture danielstaleiny  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

danialkhansari picture danialkhansari  路  3Comments

ksushilmaurya picture ksushilmaurya  路  3Comments

Brekmister picture Brekmister  路  3Comments