konstantine

konstantine

How to get Phoenix to do some HTTP/2 server pushing

HTTP/2 has been around for a while, but I have not been able to find any online guidance on how to implement server push in Phoenix. My understanding is that Plug.Conn.push!/3 should do the job, but it isn’t working for me, at least not according to my Chrome and this online test. There are a few gray areas in which the culprit may be residing:

• push/3’s path: I presume that this should be the URL path with the query string, not 100% sure

• push/3’s headers: again, this might be something like [{“accept”, “text/css”}] – if necessary at all

• the port number: my https server is not running on 443, can my v2.7 Cowboy figure this out automatically? If not, where do I specify the port number?

The conn structs before and after the application of push/3 are identical, does this indicate a noop? How does one know definitively that the push has been successful?

Most Liked

konstantine

konstantine

Yes, I am using the latest Cowboy (v2.7), while Chrome confirms that my resources are downloaded using h2, i.e. HTTP/2 over HTTPS.

The requests are naturally made on port 443, but then forwarded to another port on the server (by my router). Cowboy should know about this, given that :port is supplied to the Endpoint as part of the :https list, all of which is Plug.Cowboy-related. Moreover, according to this post, a request to a port other than 443 should not be a problem.

I think that feedback is the key issue here. How do we know that the push has been successful? Is the conn struct supposed to be affected by the application of push/3, or is its operation a mere side-effect? Can we depend on push!/3 to always raise when the operation fails to push, or not?

OvermindDL1

OvermindDL1

Might need to ask one of the @Phoenix-Core-Team people then (is this a good case to ping them, I code-fenced it so they aren’t…)? ^.^;

konstantine

konstantine

Thanks, I think I’ll simply wrap this issue up by making some final observations:

Firefox eventually showed that my server push configuration actually worked. This means that online tests like the one I used and Chrome do not necessarily provide conclusive feedback. It also means that push/3 produces a side-effect that seems to leave no trace on the conn.

Why did Chrome, in particular, not mark my resources as pushed? There are several possible reasons (incl. that server push was working), which may or may not have to do with the Phoenix implementation, but the SSL certificate (see SAN issue mentioned in the docs) was not the one responsible in my case.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New

Other popular topics Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement