mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 20:50:24 +00:00
Small guide fixes
This commit is contained in:
parent
d3f15cfd8b
commit
f104da9322
2 changed files with 10 additions and 9 deletions
|
@ -193,8 +193,8 @@ callback.
|
||||||
|
|
||||||
If you implement the methods PUT, POST and/or PATCH,
|
If you implement the methods PUT, POST and/or PATCH,
|
||||||
you must implement the `content_types_accepted` callback,
|
you must implement the `content_types_accepted` callback,
|
||||||
and one `AcceptResource` callback for each content-type
|
and one `AcceptCallback` callback for each content-type
|
||||||
it returns. Prefix the `AcceptResource` callback names
|
it returns. Prefix the `AcceptCallback` callback names
|
||||||
with `from_` for clarity. For example, `from_html` or
|
with `from_` for clarity. For example, `from_html` or
|
||||||
`from_json`.
|
`from_json`.
|
||||||
|
|
||||||
|
|
|
@ -57,18 +57,19 @@ be:
|
||||||
|
|
||||||
[source,erlang]
|
[source,erlang]
|
||||||
----
|
----
|
||||||
init(Req, State) ->
|
init(Req0, State) ->
|
||||||
case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req) of
|
case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req0) of
|
||||||
undefined ->
|
undefined ->
|
||||||
{cowboy_websocket, Req, State};
|
{cowboy_websocket, Req0, State};
|
||||||
Subprotocols ->
|
Subprotocols ->
|
||||||
case lists:keymember(<<"mqtt">>, 1, Subprotocols) of
|
case lists:keymember(<<"mqtt">>, 1, Subprotocols) of
|
||||||
true ->
|
true ->
|
||||||
Req2 = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>,
|
Req = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>,
|
||||||
<<"mqtt">>, Req),
|
<<"mqtt">>, Req0),
|
||||||
{cowboy_websocket, Req2, State};
|
{cowboy_websocket, Req, State};
|
||||||
false ->
|
false ->
|
||||||
{stop, Req, State}
|
Req = cowboy_req:reply(400, Req0),
|
||||||
|
{ok, Req, State}
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
----
|
----
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue