1 defmodule Pleroma.HTTP do
3 alias Pleroma.HTTP.Connection
4 alias Pleroma.HTTP.RequestBuilder, as: Builder
6 def request(method, url, body \\ "", headers \\ [], options \\ []) do
8 process_request_options(options)
9 |> process_sni_options(url)
12 |> Builder.method(method)
13 |> Builder.headers(headers)
14 |> Builder.opts(options)
16 |> Builder.add_param(:body, :body, body)
18 |> (&Tesla.request(Connection.new(), &1)).()
21 defp process_sni_options(options, nil), do: options
22 defp process_sni_options(options, url) do
24 host = uri.host |> to_charlist()
27 "https" -> options ++ [ssl: [server_name_indication: host]]
32 def process_request_options(options) do
33 config = Application.get_env(:pleroma, :http, [])
34 proxy = Keyword.get(config, :proxy_url, nil)
35 options = options ++ [adapter: [pool: :default]]
39 _ -> options ++ [proxy: proxy]
43 def get(url, headers \\ [], options \\ []),
44 do: request(:get, url, "", headers, options)
46 def post(url, body, headers \\ [], options \\ []),
47 do: request(:post, url, body, headers, options)