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, url) do
23 host = uri.host |> to_charlist()
26 "https" -> options ++ [ssl: [server_name_indication: host]]
31 def process_request_options(options) do
32 config = Application.get_env(:pleroma, :http, [])
33 proxy = Keyword.get(config, :proxy_url, nil)
34 options = options ++ [adapter: [pool: :default]]
38 _ -> options ++ [proxy: proxy]
42 def get(url, headers \\ [], options \\ []),
43 do: request(:get, url, "", headers, options)
45 def post(url, body, headers \\ [], options \\ []),
46 do: request(:post, url, body, headers, options)