I'm a poor lonesome Cowboy,
and a long way from home...
Loïc Hoguin (@lhoguin), Nine Nines
Literally
HTTP/2 even more so
info/3
callback
{[
{headers, fin, 100, Headers},
{flow, 64000},
{spawn, Pid, 5000}
], State}.
gen_statem
init(StreamID, Req, Opts) → {Commands, State}
data(StreamID, IsFin, Data, State) → {Commands, State}
info(StreamID, Msg, State) → {Commands, State}
terminate(StreamID, Reason, State) → _
early_error(StreamID, Reason, PartialReq, Resp, Opts) → Resp
#{
middlewares ⇒
[cowboy_router, cowboy_handler],
stream_handlers ⇒
[cowboy_compress_h, cowboy_stream_h]
}
execute(Req0, Env0) →
case do_something(Req0, Env0) of
{ok, Req, Env} →
{ok, Req, Env};
error →
{stop, Req0}
end.
data(StreamID, IsFin, Data, State=#state{next=Next0}) →
{Commands0, Next} = cowboy_stream:data(
StreamID, IsFin, Data, Next0),
fold(Commands0, State#state{next=Next}).
data(StreamID, IsFin, Data0, State=#state{next=Next0}) →
Data = do_something(Data0),
{Commands0, Next} = cowboy_stream:data(
StreamID, IsFin, Data, Next0),
{Commands0, State#state{next=Next}}.
loop() →
receive
Msg →
do_something(Msg),
loop()
end.
cowboy_rest
{error, Reason}
Reason =
{connection_error,
protocol_error,
'The preface sequence must be followed
by a SETTINGS frame. (RFC7540 3.5)'}
uri(Req :: cowboy_req:req()) → uri(Req, #{})
uri(Req :: cowboy_req:req(), Opts) → URI :: iodata()
Opts :: #{
scheme ⇒ iodata() | undefined,
host ⇒ iodata() | undefined,
port ⇒ inet:port_number() | undefined,
path ⇒ iodata() | undefined,
qs ⇒ iodata() | undefined,
fragment ⇒ iodata() | undefined
}
read_body(Req :: cowboy_req:req())
→ read_body(Req, #{})
read_body(Req :: cowboy_req:req(), Opts)
→ {ok, Data :: binary(), Req}
| {more, Data :: binary(), Req}
Opts :: #{
length ⇒ non_neg_integer(),
period ⇒ non_neg_integer(),
timeout ⇒ timeout()
}
Use :=
instead of =>
For RFCs, at least one test per relevant MUST/SHOULD.
Document in the test suite what couldn't be tested.
Every function, argument, option must have a test.
Taking lessons from PHP
erl_tracer
NIFAnd eventually release Cowboy 3.0
Finally build that REST framework
Make (the true) REST easily accessible