HTTP/2 Server Push Not working with Zeit Now

672 Views Asked by At

In my project, I am trying to do HTTP/2 Server Push as Zeit support HTTP/2.

So, I added the necessary link header to my request.

HTTP/2 Push Header

But when I am checking the network tab, the initiator is showing as Other instead of Push/Other.

Push not showing

Then I checked another site: https://http2-server-push-demo.keksi.io/ and here Push is clearly showing.

Push working header

Push working screenshot

What is going on here? I am not understanding. I am using Now CLI v16.4.4. Can anyone help?

Some debug info

Just in case it is needed here are some command outputs:

Command: curl --http2 -v https://example.com

curl --http2 -v https://ccrewards.in
 * Rebuilt URL to: https://ccrewards.in/
 *   Trying 13.234.90.190...
 * TCP_NODELAY set
 * Connected to ccrewards.in (13.234.90.190) port 443 (#0)
 * ALPN, offering h2
 * ALPN, offering http/1.1
 * successfully set certificate verify locations:
 *   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
 * TLSv1.2 (OUT), TLS handshake, Client hello (1):
 * TLSv1.2 (IN), TLS handshake, Server hello (2):
 * TLSv1.2 (IN), TLS handshake, Certificate (11):
 * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
 * TLSv1.2 (IN), TLS handshake, Server finished (14):
 * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
 * TLSv1.2 (OUT), TLS change cipher, Client hello (1):
 * TLSv1.2 (OUT), TLS handshake, Finished (20):
 * TLSv1.2 (IN), TLS handshake, Finished (20):
 * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
 * ALPN, server accepted to use h2
 * Server certificate:
 *  subject: CN=ccrewards.in
 *  start date: Oct 25 06:44:21 2019 GMT
 *  expire date: Jan 23 06:44:21 2020 GMT
 *  subjectAltName: host "ccrewards.in" matched cert's "ccrewards.in"
 *  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
 *  SSL certificate verify ok.
 * 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 0x7fffe6a71b70)
> GET / HTTP/2
> Host: ccrewards.in
> User-Agent: curl/7.58.0
> Accept: */*
>
 * Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200
< content-type: text/html; charset=utf-8
< link: </css/bootstrap.min.css>; rel=preload; as=style, </css/placeholder-loading.min.css>; rel=preload; as=style
< date: Mon, 28 Oct 2019 18:06:54 GMT
< vary: User-Agent, Accept-Encoding
< content-encoding: gzip
< content-length: 28149
< etag: "4eadf-E5nKTWVXCBjTRiqdEed4eCgcd6A"
< accept-ranges: none
< cache-control: public, max-age=0, must-revalidate
< x-now-cache: STALE
< x-now-trace: bom1
< server: now
< x-now-id: bom1:bom1:48cbv-1572288058858-8bf8eca0e432
< strict-transport-security: max-age=63072000
<
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
 * Failed writing body (0 != 15963)
 * Connection #0 to host ccrewards.in left intact
1

There are 1 best solutions below

0
Barry Pollard On

Just because a server supports HTTP/2 does not mean it supports all features of HTTP/2. And even if it does, it doesn't mean it initiates push with the link header - that is not defined in the HTTP/2 spec but is a method many (but not all) servers use to initiate HTTP/2 push.

Checking out your site with nghttp (better than curl for HTTP/2 debugging), I cannot see the frames being pushed and from the server.

I'm not familair with Zeit-now but a quick Google suggests it might be built on top of Node which does not support link headers as a method of Push and instead you must use http2stream.pushStream to explicitly initiate an HTTP/2 push.