mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
prepend host header
This commit is contained in:
parent
9468ede4e3
commit
5e5e3d3b45
1 changed files with 9 additions and 2 deletions
|
@ -2,19 +2,26 @@ defmodule Philomena.Http do
|
||||||
@user_agent ["User-Agent": "Mozilla/5.0 (X11; Philomena; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0"]
|
@user_agent ["User-Agent": "Mozilla/5.0 (X11; Philomena; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0"]
|
||||||
|
|
||||||
def get!(url, headers \\ [], options \\ []) do
|
def get!(url, headers \\ [], options \\ []) do
|
||||||
headers = Keyword.merge(@user_agent, headers)
|
headers = Keyword.merge(@user_agent, headers) |> add_host(url)
|
||||||
options = Keyword.merge(options, proxy: proxy_host())
|
options = Keyword.merge(options, proxy: proxy_host())
|
||||||
|
|
||||||
HTTPoison.get!(url, headers, options)
|
HTTPoison.get!(url, headers, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def head!(url, headers \\ [], options \\ []) do
|
def head!(url, headers \\ [], options \\ []) do
|
||||||
headers = Keyword.merge(@user_agent, headers)
|
headers = Keyword.merge(@user_agent, headers) |> add_host(url)
|
||||||
options = Keyword.merge(options, proxy: proxy_host())
|
options = Keyword.merge(options, proxy: proxy_host())
|
||||||
|
|
||||||
HTTPoison.head!(url, headers, options)
|
HTTPoison.head!(url, headers, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add host for caching proxies, since hackney doesn't do it for us
|
||||||
|
defp add_host(headers, url) do
|
||||||
|
%{host: host} = URI.parse(url)
|
||||||
|
|
||||||
|
Keyword.merge(["Host": host], headers)
|
||||||
|
end
|
||||||
|
|
||||||
defp proxy_host do
|
defp proxy_host do
|
||||||
Application.get_env(:philomena, :proxy_host)
|
Application.get_env(:philomena, :proxy_host)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue