Okay so keep in mind, I am ~1 week into Elixir / Phoenix coming from PHP so my thinking is not fully converted over. But in PHP-land you can capture a rendered view before sending it out; i.e., render all the views, put it into a variable, do something with it.
Some Example Cases:
- Strip whitespace out of rendered views.
- Write the rendered HTML to a file (audit, logging?)
Generally I just want to be able to:
- Capture the routed request into a variable
- Stop traditional routing, and do something else
But no matter where I seem to access “conn” from in Phoenix I can’t seem to pull out the response body, as if it were compiled or rendered HTML. The conn.body always seems to be nil.
Like I get all this stuff…
:phoenix_action => :index,
:phoenix_controller => DemoWeb.PageController,
:phoenix_endpoint => DemoWeb.Endpoint,
:phoenix_flash => %{},
:phoenix_format => “html”,
:phoenix_layout => {DemoWeb.LayoutView, :app},
:phoenix_request_logger => {“request_logger”, “request_logger”},
:phoenix_root_layout => {DemoWeb.LayoutView, :root},
:phoenix_router => DemoWeb.Router,
:phoenix_template => “index.html”,
:phoenix_view => DemoWeb.PageView,
Along with response stuff, etc., but…
resp_body: nil,
resp_cookies: %{},
resp_headers: [
{“content-type”, “text/html; charset=utf-8”},
{“cache-control”, “max-age=0, private, must-revalidate”},
{“x-request-id”, “Fz89qzaSZgX7k4IAAAAm”},
{“x-frame-options”, “SAMEORIGIN”},
{“x-xss-protection”, “1; mode=block”},
{“x-content-type-options”, “nosniff”},
{“x-download-options”, “noopen”},
{“x-permitted-cross-domain-policies”, “none”},
{“cross-origin-window-policy”, “deny”}
],
So where is my resp_body (after rendering views) if I were to need that?
Hopefully I am making sense. Sorry.