Add a 'websocket_protocol_header' option to fix the missing 'Sec-Websocket-Protocol' header of WeChat WebSocket Connection
This commit is contained in:
parent
94402f4297
commit
0ffa2d00d0
|
@ -59,7 +59,7 @@ handle_request('POST', "/mqtt/publish", Req) ->
|
|||
handle_request('GET', "/mqtt", Req) ->
|
||||
lager:info("WebSocket Connection from: ~s", [Req:get(peer)]),
|
||||
Upgrade = Req:get_header_value("Upgrade"),
|
||||
Proto = Req:get_header_value("Sec-WebSocket-Protocol"),
|
||||
Proto = check_protocol_header(Req),
|
||||
case {is_websocket(Upgrade), Proto} of
|
||||
{true, "mqtt" ++ _Vsn} ->
|
||||
emqttd_ws:handle_request(Req);
|
||||
|
@ -83,6 +83,18 @@ handle_request(Method, Path, Req) ->
|
|||
lager:error("Unexpected HTTP Request: ~s ~s", [Method, Path]),
|
||||
Req:not_found().
|
||||
|
||||
check_protocol_header(Req) ->
|
||||
case emqttd:env(websocket_protocol_header, false) of
|
||||
true -> get_protocol_header(Req);
|
||||
false -> "mqtt-v3.1.1"
|
||||
end.
|
||||
|
||||
get_protocol_header(Req) ->
|
||||
case Req:get_header_value("Emq-WebSocket-Protocol") of
|
||||
undefined -> Req:get_header_value("Sec-WebSocket-Protocol");
|
||||
Proto -> Proto
|
||||
end.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% HTTP Publish
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue