projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'support/oauth_fetch_token' into 'develop'
[akkoma]
/
lib
/
pleroma
/
reverse_proxy.ex
diff --git
a/lib/pleroma/reverse_proxy.ex
b/lib/pleroma/reverse_proxy.ex
index 64c3c3a19407e4fbf6391af2a5a6a7b85d74ca6c..ad9dc82fe02a653bd9fd3a1272b509b4a5b430d2 100644
(file)
--- a/
lib/pleroma/reverse_proxy.ex
+++ b/
lib/pleroma/reverse_proxy.ex
@@
-1,11
+1,11
@@
defmodule Pleroma.ReverseProxy do
defmodule Pleroma.ReverseProxy do
- @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-
none-match
range)
+ @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-
unmodified-since if-none-match if-range
range)
@resp_cache_headers ~w(etag date last-modified cache-control)
@keep_resp_headers @resp_cache_headers ++
@resp_cache_headers ~w(etag date last-modified cache-control)
@keep_resp_headers @resp_cache_headers ++
- ~w(content-type content-disposition content-
length
accept-ranges vary)
+ ~w(content-type content-disposition content-
encoding content-range
accept-ranges vary)
@default_cache_control_header "public, max-age=1209600"
@valid_resp_codes [200, 206, 304]
@default_cache_control_header "public, max-age=1209600"
@valid_resp_codes [200, 206, 304]
- @max_read_duration :timer.
minutes(2
)
+ @max_read_duration :timer.
seconds(30
)
@max_body_length :infinity
@methods ~w(GET HEAD)
@max_body_length :infinity
@methods ~w(GET HEAD)
@@
-101,7
+101,7
@@
defmodule Pleroma.ReverseProxy do
end
with {:ok, code, headers, client} <- request(method, url, req_headers, hackney_opts),
end
with {:ok, code, headers, client} <- request(method, url, req_headers, hackney_opts),
- :ok <- header_leng
ht
_constraint(headers, Keyword.get(opts, :max_body_length)) do
+ :ok <- header_leng
th
_constraint(headers, Keyword.get(opts, :max_body_length)) do
response(conn, client, url, code, headers, opts)
else
{:ok, code, headers} ->
response(conn, client, url, code, headers, opts)
else
{:ok, code, headers} ->
@@
-225,6
+225,14
@@
defmodule Pleroma.ReverseProxy do
end)
end
end)
end
+ defp get_content_type(headers) do
+ {_, content_type} =
+ List.keyfind(headers, "content-type", 0, {"content-type", "application/octet-stream"})
+
+ [content_type | _] = String.split(content_type, ";")
+ content_type
+ end
+
defp put_resp_headers(conn, headers) do
Enum.reduce(headers, conn, fn {k, v}, conn ->
put_resp_header(conn, k, v)
defp put_resp_headers(conn, headers) do
Enum.reduce(headers, conn, fn {k, v}, conn ->
put_resp_header(conn, k, v)
@@
-253,12
+261,11
@@
defmodule Pleroma.ReverseProxy do
end
defp build_resp_headers(headers, opts) do
end
defp build_resp_headers(headers, opts) do
- headers =
- headers
- |> Enum.filter(fn {k, _} -> k in @keep_resp_headers end)
- |> build_resp_cache_headers(opts)
- |> build_resp_content_disposition_header(opts)
- |> (fn headers -> headers ++ Keyword.get(opts, :resp_headers, []) end).()
+ headers
+ |> Enum.filter(fn {k, _} -> k in @keep_resp_headers end)
+ |> build_resp_cache_headers(opts)
+ |> build_resp_content_disposition_header(opts)
+ |> (fn headers -> headers ++ Keyword.get(opts, :resp_headers, []) end).()
end
defp build_resp_cache_headers(headers, opts) do
end
defp build_resp_cache_headers(headers, opts) do
@@
-274,8
+281,7
@@
defmodule Pleroma.ReverseProxy do
defp build_resp_content_disposition_header(headers, opts) do
opt = Keyword.get(opts, :inline_content_types, @inline_content_types)
defp build_resp_content_disposition_header(headers, opts) do
opt = Keyword.get(opts, :inline_content_types, @inline_content_types)
- {_, content_type} =
- List.keyfind(headers, "content-type", 0, {"content-type", "application/octect-stream"})
+ content_type = get_content_type(headers)
attachment? =
cond do
attachment? =
cond do
@@
-292,7
+298,7
@@
defmodule Pleroma.ReverseProxy do
end
end
end
end
- defp header_leng
ht
_constraint(headers, limit) when is_integer(limit) and limit > 0 do
+ defp header_leng
th
_constraint(headers, limit) when is_integer(limit) and limit > 0 do
with {_, size} <- List.keyfind(headers, "content-length", 0),
{size, _} <- Integer.parse(size),
true <- size <= limit do
with {_, size} <- List.keyfind(headers, "content-length", 0),
{size, _} <- Integer.parse(size),
true <- size <= limit do
@@
-306,7
+312,7
@@
defmodule Pleroma.ReverseProxy do
end
end
end
end
- defp header_leng
ht
_constraint(_, _), do: :ok
+ defp header_leng
th
_constraint(_, _), do: :ok
defp body_size_constraint(size, limit) when is_integer(limit) and limit > 0 and size >= limit do
{:error, :body_too_large}
defp body_size_constraint(size, limit) when is_integer(limit) and limit > 0 and size >= limit do
{:error, :body_too_large}
@@
-319,7
+325,6
@@
defmodule Pleroma.ReverseProxy do
if duration > max do
{:error, :read_duration_exceeded}
else
if duration > max do
{:error, :read_duration_exceeded}
else
- Logger.debug("Duration #{inspect(duration)}")
{:ok, {duration, :erlang.system_time(:millisecond)}}
end
end
{:ok, {duration, :erlang.system_time(:millisecond)}}
end
end