Fl4m3Ph03n1x
How to gzip responses from 1 endpoint in Phoenix?
Background
We have an old app using Phoenix 1.2 and we have dozens of endpoints. We want 1 of these endpoints to have its responses compressed via gzip (or whatever the default is that Phoenix uses).
Code
We have all our endpoints defined in a file like this:
defmodule MyApp.Router do
use MyApp.Web, :router scope "/", MyApp do
get("/bananas", BananasController, :bananas)
end
end
However, after checking specifications for Phoenix 1.2, we didn’t find a way to compress only 1 endpoint.
We found something in SO, but we don’t understand how we can apply this to our app:
Question
How do we adapt our code to compress responses from only the /bananas endpoint?
Marked As Solved
hauleth
There is no way to do such, as this is feature of the adapter (Cowboy in most common example), not endpoint per se. So unless you run separate adapter for that controller then there is no way to compress responses.
Also Liked
outlog
maybe use send_resp and do it manually eg use :zlib.gzip(response) and add the appropriate headers?
Fl4m3Ph03n1x
That’s the only way we can do it, apparently, yes.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









