arizona_http (arizona v0.4.0)

View Source

Shared HTTP render pipeline for transport adapters that serve an Arizona view as the page response.

Runs route middlewares against an already-wrapped arizona_req:request(), then dispatches to arizona_render:render_view/2 and returns either a halt signal (middleware refused to continue), the rendered page body, or a crash/error page body. The caller is responsible for wrapping the native request beforehand and translating the result into its transport's native reply shape.

Flow

  1. Run arizona_middleware:apply_middlewares/3 with the route's bindings.
  2. On {halt, HaltReq} -- return {halt, HaltReq} unchanged; the caller decodes the stashed redirect (arizona_req:halted_redirect/1) or status and ships the reply (a 403 when the middleware stashed neither).
  3. On {cont, Req1, Bindings1} -- call arizona_render:render_view/2 with the route's layout/on_mount. Return {ok, 200, ContentType, Page, Req1} or, on crash or a stashed hot-reload error, {error, 500, ContentType, ErrorPage, Req1} (the threaded req carries any response headers/cookies for the transport to flush). ContentType is the rendered document's media type, answered by its render backend, so a ?native route serves JSON and an HTML one HTML.

Summary

Functions

Runs the full render pipeline for Handler against an already-wrapped arizona_req:request().

render/3 folded into the response a server adapter sends: a halt becomes its arizona_req:halt_reply/1 (empty body), a rendered page (or its error page) gets arizona_req:flush/1's lines then its content-type. Either way the session is committed and the header lines are in send order, so the adapter only adds its own framing (a content-length) and replies.

Types

error_info()

-nominal error_info() ::
             #{class := error | exit | throw,
               reason := term(),
               stacktrace := erlang:stacktrace(),
               reload_url => binary() | undefined}.

reply()

-nominal reply() :: {arizona_req:resp_status(), [{binary(), binary()}], iodata(), arizona_req:request()}.

result()

-nominal result() ::
             {halt, arizona_req:request()} |
             {ok, arizona_req:resp_status(), ContentType :: binary(), iolist(), arizona_req:request()} |
             {error, 500, ContentType :: binary(), iolist(), arizona_req:request()}.

Functions

render(Handler, ArzReq, Opts)

-spec render(Handler, ArzReq, Opts) -> result()
                when
                    Handler :: module(),
                    ArzReq :: arizona_req:request(),
                    Opts :: arizona_live:route_opts().

Runs the full render pipeline for Handler against an already-wrapped arizona_req:request().

reply(Handler, ArzReq, Opts)

-spec reply(Handler, ArzReq, Opts) -> reply()
               when
                   Handler :: module(),
                   ArzReq :: arizona_req:request(),
                   Opts :: arizona_live:route_opts().

render/3 folded into the response a server adapter sends: a halt becomes its arizona_req:halt_reply/1 (empty body), a rendered page (or its error page) gets arizona_req:flush/1's lines then its content-type. Either way the session is committed and the header lines are in send order, so the adapter only adds its own framing (a content-length) and replies.