Module z_sites_dispatcher

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

Copyright © 2009-2021 Marc Worrell

Behaviours: cowboy_middleware, gen_server.

Authors: Marc Worrell (marc@worrell.nl).

Description

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

Data Types

bindings()

bindings() = [dispatch_compiler:binding()]

dispatch()

dispatch() = #dispatch_controller{dispatch_rule = atom(), controller = atom(), controller_options = list(), path_tokens = [binary()], bindings = bindings(), context = z:context()} | #dispatch_nomatch{site = atom(), host = binary(), path_tokens = [binary()], bindings = bindings(), context = #context{} | undefined} | redirect() | redirect_protocol() | stop_request()

dispatch_rule()

dispatch_rule() = dispatch_compiler:dispatch_rule()

hostname()

hostname() = binary() | string()

redirect()

redirect() = {redirect, Site::atom(), NewPathOrURI::binary() | undefined, IsPermanent::boolean()}

redirect_protocol()

redirect_protocol() = {redirect_protocol, http | https, Host::binary(), IsPermanent::boolean()}

stop_request()

stop_request() = {stop_request, pos_integer()}

trace()

trace() = #{path := binary() | [binary()] | undefined, step := trace_step(), args := proplists:proplist()}

trace_step()

trace_step() = undefined | match | try_match | dispatch_rewrite | forced_protocol_switch | notify_dispatch | rewrite_id | rewrite_match | rewrite_nomatch

Function Index

code_change/3Convert process state when code is changed.
collect_dispatchrules/0Collect all dispatch rules for all running sites, normalize and filter them.
collect_dispatchrules/1Collect all dispatch rules for all sites, normalize and filter them.
dispatch/2Match the host and path to a dispatch rule.
dispatch/5
dispatch_trace/2
dispatch_trace/3
execute/2Cowboy middleware, route the new request.
fetch_dispatchinfo/1Fetch dispatch rules for a specific site.
get_fallback_site/0Retrieve the fallback site.
get_site_for_hostname/1Fetch the site handling the given hostname (with optional port) (debug function).
handle_call/3Trap unknown calls.
handle_cast/2Load all dispatch rules, if anything changed then recompile the dispatcher(s).
handle_info/2Handling all non call/cast messages.
init/1Initiates the server.
is_bind_language/2Callback for the dispatch compiler, try to bind a language.
start_link/0Starts the server.
start_link/1
terminate/2This function is called by a gen_server when it is about to terminate.
update_dispatchinfo/0Collect dispatch information from all sites and recompiles the dispatch rules.
update_hosts/0Update the host/site mappings.

Function Details

code_change/3

code_change(OldVsn, State, Extra) -> {ok, NewState}

Convert process state when code is changed

collect_dispatchrules/0

collect_dispatchrules() -> any()

Collect all dispatch rules for all running sites, normalize and filter them.

collect_dispatchrules/1

collect_dispatchrules(Site) -> any()

Collect all dispatch rules for all sites, normalize and filter them.

dispatch/2

dispatch(Req::cowboy_req:req(), Env::cowboy_middleware:env()) -> dispatch()

Match the host and path to a dispatch rule.

dispatch/5

dispatch(Method::binary() | string(), Host::binary() | string(), Path::binary() | string(), IsSsl::boolean(), OptTracerPid::pid() | undefined) -> dispatch()

dispatch_trace/2

dispatch_trace(Path::binary(), Context::z:context()) -> {ok, [trace()]} | {error, timeout}

dispatch_trace/3

dispatch_trace(Protocol::http | https, Path::binary(), Context::z:context()) -> {ok, [trace()]} | {error, timeout}

execute/2

execute(Req, Env) -> {ok, Req, Env} | {stop, Req}

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_dispatchinfo/1

fetch_dispatchinfo(SiteOrContext) -> any()

Fetch dispatch rules for a specific site.

get_fallback_site/0

get_fallback_site() -> {ok, atom()} | undefined

Retrieve the fallback site.

get_site_for_hostname/1

get_site_for_hostname(Hostname::string() | binary() | '*') -> {ok, atom()} | undefined

Fetch the site handling the given hostname (with optional port) (debug function)

handle_call/3

handle_call(Message::Request, From, State) -> {reply, Reply, State} | {reply, Reply, State, Timeout} | {noreply, State} | {noreply, State, Timeout} | {stop, Reason, Reply, State} | {stop, Reason, State}

Trap unknown calls

handle_cast/2

handle_cast(Message::Msg, State) -> {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}

Load all dispatch rules, if anything changed then recompile the dispatcher(s)

handle_info/2

handle_info(Info, State) -> any()

Handling all non call/cast messages

init/1

init(Args) -> {ok, State} | {ok, State, Timeout} | ignore | {stop, Reason}

Initiates the server.

is_bind_language/2

is_bind_language(Match, Context) -> any()

Callback for the dispatch compiler, try to bind a language

start_link/0

start_link() -> {ok, pid()} | ignore | {error, term()}

Starts the server

start_link/1

start_link(Args::list()) -> {ok, pid()} | ignore | {error, term()}

terminate/2

terminate(Reason, State) -> void()

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.

update_dispatchinfo/0

update_dispatchinfo() -> ok

Collect dispatch information from all sites and recompiles the dispatch rules.

update_hosts/0

update_hosts() -> ok

Update the host/site mappings


Generated by EDoc