Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do HTTP/2 and CNAME work together?

I don't know exactly how to ask it, so I will try to explain with an example.

I have these resources on example.com, an HTTP/2 enabled server:

//example.com/css/file.css
//example.com/js/file.js
//example.com/images/file.png

What I want is to load one of these files through an alias domain cdn.example2.com that points to the domain example.com. So, the actual resources inside the HTML should look like:

//example.com/css/file.css
//cdn.example2.com/js/file.js   -> points to //example.com/js/file.js
//example.com/images/file.png

My question here is: Shall all the resources in the second example be loaded by the browser over a single connection as they will be loaded when there is no alias domain?

Thanks for help.

like image 586
Hamid Sarfraz Avatar asked Dec 07 '15 18:12

Hamid Sarfraz


Video Answer


2 Answers

If the aliases resolve to different IPs, there is no way the resources can be loaded over the same connection (called "connection re-use" by HTTP/2, if I'm not mistaken). That's a problem with CDNs from here on.

But for your peace of mind and utter rejoice of CDNs, connection re-use is a tricky thing and you may not have it even if all your domains resolve to the same IP, as is the case in your question.

To be future proof, you may want to ensure that your sites have the certificate extensions configured correctly to enable connection re-use.

In the current versions of Firefox and Chrome, I haven't observed connection re-use, even after crafting the certificates with all due care, and of course being sure that the two domains point to the same IP.

And just some food for thoughts: HTTP/2 over TLS requires SNI, which happens only when openning a connection. So when you connect for the first time to one domain, say example.com, the server obtains SNI data. But the server won't obtain such data if the same connection is re-used to send a request to cdn.example.com. Some servers or usage scenarios may be sensitive to this asymmetry, and that may have something to do with the way in which browsers implement (or not) connection re-use. But these are only speculations of yours truly...

like image 180
dsign Avatar answered Oct 23 '22 10:10

dsign


The specification doesn't require its reuse, but it does explicitly include information on when reuse is acceptable -- such as two hosts that resolve to the same IP address.

https://www.rfc-editor.org/rfc/rfc7540#section-9.1.1

Connections that are made to an origin server, either directly or
through a tunnel created using the CONNECT method (Section 8.3), MAY
be reused for requests with multiple different URI authority
components. A connection can be reused as long as the origin server
is authoritative (Section 10.1). For TCP connections without TLS,
this depends on the host having resolved to the same IP address.

For "https" resources, connection reuse additionally depends on
having a certificate that is valid for the host in the URI. The
certificate presented by the server MUST satisfy any checks that the
client would perform when forming a new TLS connection for the host
in the URI.

like image 43
covener Avatar answered Oct 23 '22 12:10

covener