Fix Web Push notification delivery
Finch does not automatically append header content-type: octet-stream for binary payloads.
This commit is contained in:
parent
8893a044b3
commit
e2066994b1
1
changelog.d/web_push.fix
Normal file
1
changelog.d/web_push.fix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix web push notifications not successfully delivering
|
@ -6,7 +6,11 @@ defmodule Pleroma.HTTP.WebPush do
|
|||||||
@moduledoc false
|
@moduledoc false
|
||||||
|
|
||||||
def post(url, payload, headers, options \\ []) do
|
def post(url, payload, headers, options \\ []) do
|
||||||
list_headers = Map.to_list(headers)
|
list_headers =
|
||||||
|
headers
|
||||||
|
|> Map.to_list()
|
||||||
|
|> Kernel.++([{"content-type", "octet-stream"}])
|
||||||
|
|
||||||
Pleroma.HTTP.post(url, payload, list_headers, options)
|
Pleroma.HTTP.post(url, payload, list_headers, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
45
test/pleroma/http/web_push_test.exs
Normal file
45
test/pleroma/http/web_push_test.exs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.HTTP.WebPushTest do
|
||||||
|
use ExUnit.Case
|
||||||
|
|
||||||
|
import Tesla.Mock
|
||||||
|
alias Pleroma.HTTP
|
||||||
|
|
||||||
|
@push_url "https://some-push-server/"
|
||||||
|
|
||||||
|
setup do
|
||||||
|
mock(fn
|
||||||
|
%{
|
||||||
|
method: :post,
|
||||||
|
url: @push_url,
|
||||||
|
headers: headers
|
||||||
|
} ->
|
||||||
|
if {"content-type", "octet-stream"} in headers do
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200
|
||||||
|
}
|
||||||
|
else
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 403
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
test "post" do
|
||||||
|
response =
|
||||||
|
HTTP.WebPush.post(
|
||||||
|
@push_url,
|
||||||
|
"encrypted payload",
|
||||||
|
%{"authorization" => "WebPush"},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
assert {:ok, %{status: 200}} = response
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user