3

I'm using NodeJS and trying to make a simple server request. I'd like to determine if the server is HTTP/2 or not. If it is, I'd want to use the 'http2' module to make the request. Otherwise, I'll fall back to the 'http' / 'https' modules to make the request.

With NodeJS, how can I determine if a target remote server uses HTTP/2?

TIA

Codesmith
  • 5,779
  • 5
  • 38
  • 50

1 Answers1

0

The general idea is that if you want to use http2 (if available), then you make your request from node.js using the http2 module. As part of that connection and part of the SSL/TLS negotiation, the two sides will exchange whether http2 can be used or not (via an extension called ALPN). If both sides agree on http2, then it will be used. If not, it will fall back to regular https.

Some relevant references:

How to check if website has http/2 protocol support

ALPN negotiation using node.js http2 library

If you're curious, this website: https://tools.keycdn.com/http2-test will tell you if any site supports HTTP/2 and the ALPN extension.

jfriend00
  • 683,504
  • 96
  • 985
  • 979