From f1d37a5e2399d06c8a2178c98825e77e5b381460 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 28 Feb 2019 16:02:48 +0000 Subject: [PATCH] mastodon websocket: use pattern match to get query data, robustly handle errors --- lib/pleroma/web/mastodon_api/websocket_handler.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex index f19f26b9a..edab961f0 100644 --- a/lib/pleroma/web/mastodon_api/websocket_handler.ex +++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex @@ -23,9 +23,8 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do ] @anonymous_streams ["public", "public:local", "hashtag"] - def init(req, _state) do - with {qs, req} <- :cowboy_req.qs(req), - params <- :cow_qs.parse_qs(qs), + def init(%{qs: qs} = req, _state) do + with params <- :cow_qs.parse_qs(qs), access_token <- List.keyfind(params, "access_token", 0), {_, stream} <- List.keyfind(params, "stream", 0), {:ok, user} <- allow_request(stream, access_token), @@ -39,6 +38,7 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do error -> Logger.debug("#{__MODULE__} denied connection: #{inspect(error)} - #{inspect(req)}") + {:ok, req} = :cowboy_req.reply(400, req) {:stop, req} end end -- 2.45.2