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?

First 4 of 4 Posts Switch mode

OvermindDL1

OvermindDL1

Are you using plug_cowboy 2.0+?
I know https has to be used or browsers won’t touch http2, I’m unsure if it will allow a different port either?

konstantine

konstantine OP

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 OP

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.

— All posts loaded —

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement