z_sites_dispatcher (zotonic_core v1.0.0-rc.14)

Server for matching the request path to correct site and dispatch rule.

Link to this section Summary

Functions

Convert process state when code is changed
Collect all dispatch rules for all running sites, normalize and filter them.
Collect all dispatch rules for all sites, normalize and filter them.
Match the host and path to a dispatch rule.
Dispatch a path for a host, return the extracted dispatch information and bindings. Used for matching URLs to dispatch rules and ids.
Dispatch an URL, return the extracted dispatch information and bindings. Used for matching URLs to dispatch rules and ids.
Cowboy middleware, route the new request. Continue with the cowmachine, requests a redirect or return a 400 on an unknown host. The cowmachine_proxy middleware must have been called before this.
Fetch dispatch rules for a specific site.
Retrieve the fallback site.
Fetch the site handling the given hostname (with optional port)
Fetch the site handling the given URL. Scheme is not checked.
Load all dispatch rules, if anything changed then recompile the dispatcher(s)
Handling all non call/cast messages
Initiates the server.
Callback for the dispatch compiler, try to bind a language
Starts the server
This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.
Collect dispatch information from all sites and recompiles the dispatch rules.
Update the host/site mappings

Link to this section Types

-type bindings() :: [dispatch_compiler:binding()].
-type dispatch() ::
    #dispatch_controller{} |
    #dispatch_nomatch{} |
    redirect() |
    redirect_protocol() |
    stop_request().
Link to this type

dispatch_rule/0

-type dispatch_rule() :: dispatch_compiler:dispatch_rule().
-type hostname() :: binary() | string().
-type redirect() ::
    {redirect, Site :: atom(), NewPathOrURI :: binary() | undefined, IsPermanent :: boolean()}.
Link to this type

redirect_protocol/0

-type redirect_protocol() ::
    {redirect_protocol, http | https, Host :: binary(), IsPermanent :: boolean()}.
Link to this type

stop_request/0

-type stop_request() :: {stop_request, pos_integer()}.
-type trace() ::
    #{path := binary() | [binary()] | undefined,
      step := trace_step(),
      args := proplists:proplist()}.
Link to this type

trace_step/0

-type trace_step() ::
    undefined | match | try_match | dispatch_rewrite | forced_protocol_switch | notify_dispatch |
    rewrite_id | rewrite_match | rewrite_nomatch.

Link to this section Functions

Link to this function

code_change(OldVsn, State, Extra)

Convert process state when code is changed
Link to this function

collect_dispatchrules()

Collect all dispatch rules for all running sites, normalize and filter them.
Link to this function

collect_dispatchrules(Site)

Collect all dispatch rules for all sites, normalize and filter them.
Link to this function

dispatch(Req, Env)

-spec dispatch(cowboy_req:req(), cowboy_middleware:env()) -> dispatch().
Match the host and path to a dispatch rule.
Link to this function

dispatch(Method, Host, Path, IsSsl, OptTracerPid)

-spec dispatch(binary() | string(),
         binary() | string(),
         binary() | string(),
         boolean(),
         pid() | undefined) ->
            dispatch().
Link to this function

dispatch_path(Path, Context)

-spec dispatch_path(binary() | string(), z:context()) ->
                 {ok, map()} | {error, non_neg_integer() | invalid}.
Dispatch a path for a host, return the extracted dispatch information and bindings. Used for matching URLs to dispatch rules and ids.
Link to this function

dispatch_trace(Path, Context)

-spec dispatch_trace(binary(), z:context()) -> {ok, [trace()]} | {error, timeout}.
Link to this function

dispatch_trace(Protocol, Path, Context)

-spec dispatch_trace(http | https, binary(), z:context()) -> {ok, [trace()]} | {error, timeout}.
Link to this function

dispatch_url(Url)

-spec dispatch_url(binary() | string()) -> {ok, map()} | {error, non_neg_integer() | invalid}.
Dispatch an URL, return the extracted dispatch information and bindings. Used for matching URLs to dispatch rules and ids.
Link to this function

execute(Req, Env)

-spec execute(Req, Env) -> {ok, Req, Env} | {stop, Req}
           when Req :: cowboy_req:req(), Env :: cowboy_middleware:env().
Cowboy middleware, route the new request. Continue with the cowmachine, requests a redirect or return a 400 on an unknown host. The cowmachine_proxy middleware must have been called before this.
Link to this function

fetch_dispatchinfo(SiteOrContext)

Fetch dispatch rules for a specific site.
Link to this function

get_fallback_site()

-spec get_fallback_site() -> {ok, atom()} | undefined.
Retrieve the fallback site.
Link to this function

get_site_for_hostname(Hostname)

-spec get_site_for_hostname(string() | binary() | '*') -> {ok, atom()} | undefined.
Fetch the site handling the given hostname (with optional port)
Link to this function

get_site_for_url(Url)

-spec get_site_for_url(binary() | string()) -> {ok, atom()} | undefined.
Fetch the site handling the given URL. Scheme is not checked.
Link to this function

handle_call(Message, From, State)

Trap unknown calls
Link to this function

handle_cast(Message, State)

Load all dispatch rules, if anything changed then recompile the dispatcher(s)
Link to this function

handle_info(Info, State)

Handling all non call/cast messages
Initiates the server.
Link to this function

is_bind_language(Match, Context)

Callback for the dispatch compiler, try to bind a language
-spec start_link() -> {ok, pid()} | ignore | {error, term()}.
Starts the server
Link to this function

start_link(Args)

-spec start_link(list()) -> {ok, pid()} | ignore | {error, term()}.
Link to this function

terminate(Reason, State)

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.
Link to this function

update_dispatchinfo()

-spec update_dispatchinfo() -> ok.
Collect dispatch information from all sites and recompiles the dispatch rules.
-spec update_hosts() -> ok.
Update the host/site mappings