Skip to content

HTTP2 writehead header format can't use array of arrays for headers #24466

Closed

Description

@StephenLynx

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

Activity

  1. Trott commented on Nov 25, 2018

    @Trott
    Member

    @nodejs/http2

  2. added
    http2
    on Nov 25, 2018
  3. sebdeckers commented on Nov 26, 2018

    @sebdeckers
    Contributor

    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?

    Details

    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
    

  4. jasnell commented on Nov 26, 2018

    @jasnell
    Member

    Unfortunately, we probably should support it.

  5. added
    confirmed-bug
    on Nov 26, 2018
  6. StephenLynx commented on Nov 29, 2018

    @StephenLynx
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bughttp2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions