0

Node provides this method:

http2stream.additionalHeaders(headers)

Which Sends an additional informational HEADERS frame to the connected HTTP/2 peer.

However the node codebase contains this comment:

// Sends a block of informational headers. In theory, the HTTP/2 spec
// allows sending a HEADER block at any time during a streams lifecycle,
// but the HTTP request/response semantics defined in HTTP/2 places limits
// such that HEADERS may only be sent *before* or *after* DATA frames.
// If the block of headers being sent includes a status code, it MUST be
// a 1xx informational code and it MUST be sent before the request/response
// headers are sent, or an error will be thrown.

Is it possible to send subsequent or additional HEADER blocks on a stream?

e.g. pseudo code:

stream.respond(HEADER)
stream.write(DATA)
stream.additionalHeaders(HEADER)
stream.write(DATA)
stream.end(DATA)

And:

  • if possible please provide some demo code; or

  • if not what is the point of the additionalHeaders function, and as the response event returns the header what is point of the headers event?

TrevTheDev
  • 2,616
  • 2
  • 18
  • 36

1 Answers1

1

As per the comment, the following is not valid HTTP/2:

stream.respond(HEADER)
stream.write(DATA)
stream.additionalHeaders(HEADER)
stream.write(DATA)
stream.end(DATA)

But the following is:

stream.respond(HEADER)
stream.write(DATA)
stream.additionalHeaders(HEADER)

This allows you to send a trailing header, usually used for checksums or other integrity checks for dynamically generated content that cannot be known in advance to send in first Headers request (it's much preferred to send headers in advance than after).

Barry Pollard
  • 40,655
  • 7
  • 76
  • 92