1 defmodule Pleroma.HTTP do
2 alias Pleroma.HTTP.Connection
3 alias Pleroma.HTTP.RequestBuilder, as: Builder
6 Builds and perform http request.
8 def request(method, url, body \\ "", headers \\ [], options \\ []) do
10 process_request_options(options)
11 |> process_sni_options(url)
14 |> Builder.method(method)
15 |> Builder.headers(headers)
16 |> Builder.opts(options)
18 |> Builder.add_param(:body, :body, body)
20 |> (&Tesla.request(Connection.new(), &1)).()
23 defp process_sni_options(options, nil), do: options
25 defp process_sni_options(options, url) do
27 host = uri.host |> to_charlist()
30 "https" -> options ++ [ssl: [server_name_indication: host]]
35 def process_request_options(options) do
36 config = Application.get_env(:pleroma, :http, [])
37 proxy = Keyword.get(config, :proxy_url, nil)
38 options = options ++ [adapter: [pool: :default]]
42 _ -> options ++ [proxy: proxy]
46 def get(url, headers \\ [], options \\ []),
47 do: request(:get, url, "", headers, options)
49 def post(url, body, headers \\ [], options \\ []),
50 do: request(:post, url, body, headers, options)