Does HTTP/2 need something other than server configuration to work?

Asked

Viewed 151 times

5

I already have HTTP/2 configured on the server, testing by https://tools.keycdn.com/http2-test the result is:

HTTP/2 Protocol is supported.

ALPN Extension is supported.

But looking through the access log I see that all access is still by HTTP/1.1, none by HTTP/2.

There’s something I need to do for users to start accessing over HTTP/2, maybe change a header or something like that? Or does it still depend on future browser updates to get real? Btw, the server is apache, and the application on the server is in PHP.

  • 1

    It doesn’t matter if the server has support and the client doesn’t. The logs you analyzed were requests made by a client that supports HTTP2?

  • @Costamilam I can’t say. Actually the question is just that. Being enabled on the server, it only depends on a browser behavior (which is not yet default), or can I set something that forces the browser to use HTTP/2? Is there any header, or meta that I need to add in PHP or HTML?

2 answers

7


In accordance with the apache documentation, you can control the requests PUSH through the response header Link. That is, if you will respond your client with an HTML file that depends on a CSS file and another JS, you can send them to the client via PUSH before the same need to order them.

You can do this directly in your server configuration, for each route

<Location /xxx.html>
    Header add Link "</xxx.css>;rel=preload"
    Header add Link "</xxx.js>;rel=preload"
</Location>

Or simply add the headers to the answer. With PHP you are able to do this through the function header:

<?php

header("Link </xxx.css>;rel=preload, </xxx.js>; rel=preload");

So when the client loads your HTML page you will also receive the CSS and JS files.

For the first access, which creates the connection to the server, simply inform the HTTP version during the request:

GET / HTTP/2
Host: localhost

The browser, which has HTTP/2 support, will already do this on its own. You can check this in the developer tools in your browser. Here, accessing a page on a server with HTTP/2 support, which sends via PUSH the CSS file, was:

inserir a descrição da imagem aqui

The value h1 in Protocol indicates HTTP/2 and for the CSS file, second from the list, it is possible to see Push as Iniciator of the requisition.

  • So only if I use Preload will you access by http/2?

  • @gustavox The HTTP header...

  • The header Link? But if that’s it then if I don’t use Preload, and let’s say I don’t want to load anything first, then even though I’m enabled http2 won’t be used for anything? Or it has its own header that indicates to use http2. whenever possible, even without using push?

  • @gustavox I did not understand your comment. As well "load anything before"?

  • So I don’t understand yet when http/2 is used. O push from what I understand is used when I want to upload data from a next page that I believe will be ordered right? For example. I have a form that the result opens in another page.. continues

  • Then with the header Link I can already download the CSS and JS from the next page... But what if I’m not interested in this p. e.g. Access without using this will be http/1.1. It is the use of Link header that makes you use http/2?

  • Anderson, it just depends on the browser having support after you set it up on the server? Because http2 isn’t just push, right? Your answer is cool, but it was not what I asked and I remain in doubt, since even having support no access occurs in http2. Are there few browser versions that access by http/2? Could you please complement it even if it’s something basic like "You don’t have to do anything, it depends on the browser"? Thanks

  • @gustavox I think I understand. In this case you can make the request by passing the HTTP/2 version even, for example GET / HTTP/2. I’ll see if I can find some information on how the browser handles it

  • Man, then, I was sorry, I did not pass an important info on the question (because I found it irrelevant), and that caused the difficulty for those who tried to answer. Because since who provides http2 is cloudflare, the access log does not show http2 because of this: https://support.cloudflare.com/hc/en-us/articles/214534978-Are-the-HTTP-2-or-SPDY-protocols-supported-between-CloudFlare-and-the-origin-server- [continue]

  • Then I tested by the inspector with the help of this providential question https://stackoverflow.com/questions/12213421/how-can-i-view-the-protocol-used-in-chrome-developer-tools-network-tab and saw that the connections are already being in http2. So I think that both you and the other answer focused on what is possible to manipulate at the application level (the server push). In fact, I think in your answer, all that remains is to say that once you have configured it correctly on the server, you do not need to do anything. In my case it was enough to click a button. :)

  • I mean, to use the server push needs, but for the other resources (multiplexing, binary headers etc) just configure on the server that the H2 header is already sent, so at the application level you do not need to do anything unless you want to use the server push...

  • Is that right? Haha

  • 1

    @Yes, everything indicates that yes. From what I read, the browser (currently) will already check if the server allows the use of HTTP/2 and will use, but I am looking for official information on this.

  • Yes, but only a few browsers don’t support it, a few, and if it doesn’t, it automatically drops to HTTP 1.1. Being configured on the server and sending the header H2 https://http2.github.io/http2-spec/#versioning, it already connects to http/2. Magic. :)

  • The browser that already supports: https://caniuse.com/#feat=http2

Show 10 more comments

1

First, it may be the browser of clients that do not support HTTP/2 and its features. For example, sometimes the browser does not support the server push and ignores it (as is the case with Safari 9.0).

However, there is the configuration by the server, in the application itself, which in case you have to check if it was done. You must include in the Sponse a Link header that lists the Urls of the additional features that will be targeted by the server push, for sending at once to the customer. Then the server, in case it supports HTTP/2 and is configured (as it seems to me in your case), reads this header and does the appropriate actions to turn into a server push.

And, as explained in the link article below, the servers need somehow to receive from the developers, ie, be informed, which resources should be targeted server push. There is no rule yet, but there seems to be a consensus forming around using Web Linking RFC for this communication. This is how Apache does it and this is how Google App Engine does it.

The RFC syntax of Web Linking sends us the URL of the resource, its type and the relationship we have with it. In case, for the server push to work, we want a Preload relationship.

Give a beautiful one in this article: https://blog.caelum.com.br/http2-server-push-na-pratica/

  • So, as I said in the other answer, I did not pass an important info on the question (because I found it irrelevant), and that caused the difficulty for those who tried to answer. Since who provides http2 is cloudflare, the access log does not show http2 access because cloudflare does not use it between it and the source server. But thanks for the answer. + 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.