Skip to content

Commit

Permalink
Deprecate server pushes given it is being removed from browsers and c…
Browse files Browse the repository at this point in the history
…lients
  • Loading branch information
josevalim committed Aug 20, 2022
1 parent 9642b31 commit cd258e7
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 28 deletions.
2 changes: 2 additions & 0 deletions lib/plug/conn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,7 @@ defmodule Plug.Conn do
resource if your certificate is not trusted. In the case of Chrome this means
a valid cert with a SAN. See https://www.chromestatus.com/feature/4981025180483584
"""
@deprecated "Most browsers and clients have removed push support"
@spec push(t, String.t(), Keyword.t()) :: t
def push(%Conn{} = conn, path, headers \\ []) do
adapter_push(conn, path, headers)
Expand All @@ -1411,6 +1412,7 @@ defmodule Plug.Conn do
Pushes a resource to the client but raises if the adapter
does not support server push.
"""
@deprecated "Most browsers and clients have removed push support"
@spec push!(t, String.t(), Keyword.t()) :: t
def push!(%Conn{adapter: {adapter, _}} = conn, path, headers \\ []) do
case adapter_push(conn, path, headers) do
Expand Down
1 change: 1 addition & 0 deletions lib/plug/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ defmodule Plug.Test do
assert {"/static/application.js", [{"accept", "application/javascript"}]} in pushes
"""
@deprecated "Most browsers and clients have removed push support"
def sent_pushes(%Conn{adapter: {Plug.Adapters.Test.Conn, %{ref: ref}}}) do
Enum.reverse(receive_pushes(ref, []))
end
Expand Down
12 changes: 0 additions & 12 deletions test/plug/adapters/test/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@ defmodule Plug.Adapters.Test.ConnTest do
assert {103, [{"link", "</script.js>; rel=preload; as=script"}]} in informational_requests
end

test "push adds to the pushes list" do
conn =
conn(:get, "/")
|> Plug.Conn.push("/static/application.css", [{"accept", "text/css"}])
|> Plug.Conn.push("/static/application.js", [{"accept", "application/javascript"}])

pushes = Plug.Test.sent_pushes(conn)

assert {"/static/application.css", [{"accept", "text/css"}]} in pushes
assert {"/static/application.js", [{"accept", "application/javascript"}]} in pushes
end

test "full URL overrides existing conn.host" do
conn_with_host = conn(:get, "http://www.elixir-lang.org/")
assert conn_with_host.host == "www.elixir-lang.org"
Expand Down
16 changes: 0 additions & 16 deletions test/plug/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -449,22 +449,6 @@ defmodule Plug.ConnTest do
)
end

test "push/3 performs a server push" do
conn = conn(:get, "/foo") |> push("/static/application.css", [{"accept", "text/plain"}])
assert {"/static/application.css", [{"accept", "text/plain"}]} in sent_pushes(conn)
end

test "push/3 works out the MIME type if not set" do
conn = conn(:get, "/foo") |> push("/static/application.css")
assert {"/static/application.css", [{"accept", "text/css"}]} in sent_pushes(conn)
end

test "push/3 will raise if the response is sent before pushing" do
assert_raise(Plug.Conn.AlreadySentError, fn ->
conn(:get, "/foo") |> send_chunked(200) |> push("/static/application.css")
end)
end

test "chunk/2 raises if send_chunked/3 hasn't been called yet" do
conn = conn(:get, "/")

Expand Down

0 comments on commit cd258e7

Please sign in to comment.