-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,9 @@ defmodule Cldr.Http do | |
This option may also be set with the | ||
`CLDR_HTTP_CONNECTION_TIMEOUT` environment variable. | ||
* `:https_proxy` is the URL of an https proxy to be used. The | ||
default is `nil`. | ||
### Returns | ||
* `{:ok, body, headers}` if the return is successful. | ||
|
@@ -189,6 +192,17 @@ defmodule Cldr.Http do | |
unidentified reasons. Please [open an issue](https://github.com/elixir-cldr/cldr/issues) | ||
if this occurs. | ||
### Https Proxy | ||
`Cldr.Http.get/2` will look for a proxy URL in the following | ||
locales in the order presented: | ||
* `options[:https_proxy] | ||
* `ex_cldr` compile-time configuration under the | ||
key `ex_cldr` -> `:https_proxy` | ||
* The environment variable `HTTPS_PROXY` | ||
* The environment variable `https_proxy` | ||
### Certificate stores | ||
In order to keep dependencies to a minimum, | ||
|
@@ -250,6 +264,12 @@ defmodule Cldr.Http do | |
hostname = String.to_charlist(URI.parse(url).host) | ||
url = String.to_charlist(url) | ||
http_options = http_opts(hostname, options) | ||
https_proxy = https_proxy(options) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
d-led
|
||
|
||
if https_proxy do | ||
%{host: host, port: port} = URI.parse(https_proxy) | ||
:httpc.set_options([{:https_proxy, {{String.to_charlist(host), port}, []}}]) | ||
end | ||
|
||
case :httpc.request(:get, {url, headers}, http_options, []) do | ||
{:ok, {{_version, 200, _}, headers, body}} -> | ||
|
@@ -337,7 +357,7 @@ defmodule Cldr.Http do | |
|> Enum.reject(&is_nil/1) | ||
|
||
@doc false | ||
def certificate_store do | ||
defp certificate_store do | ||
@certificate_locations | ||
|> Enum.find(&File.exists?/1) | ||
|> raise_if_no_cacertfile! | ||
|
@@ -376,7 +396,7 @@ defmodule Cldr.Http do | |
file | ||
end | ||
|
||
def http_opts(hostname, options) do | ||
defp http_opts(hostname, options) do | ||
default_timeout = | ||
"CLDR_HTTP_TIMEOUT" | ||
|> System.get_env(@cldr_default_timeout) | ||
|
@@ -424,7 +444,7 @@ defmodule Cldr.Http do | |
end | ||
end | ||
|
||
def preferred_ciphers do | ||
defp preferred_ciphers do | ||
preferred_ciphers = | ||
[ | ||
# Cipher suites (TLS 1.3): TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 | ||
|
@@ -447,21 +467,21 @@ defmodule Cldr.Http do | |
:ssl.filter_cipher_suites(preferred_ciphers, []) | ||
end | ||
|
||
def protocol_versions do | ||
defp protocol_versions do | ||
if otp_version() < 25 do | ||
[:"tlsv1.2"] | ||
else | ||
[:"tlsv1.2", :"tlsv1.3"] | ||
end | ||
end | ||
|
||
def preferred_eccs do | ||
defp preferred_eccs do | ||
# TLS curves: X25519, prime256v1, secp384r1 | ||
preferred_eccs = [:secp256r1, :secp384r1] | ||
:ssl.eccs() -- (:ssl.eccs() -- preferred_eccs) | ||
end | ||
|
||
def secure_ssl? do | ||
defp secure_ssl? do | ||
case System.get_env(@cldr_unsafe_https) do | ||
nil -> true | ||
"FALSE" -> false | ||
|
@@ -472,6 +492,13 @@ defmodule Cldr.Http do | |
end | ||
end | ||
|
||
defp https_proxy(options) do | ||
options[:https_proxy] || | ||
Application.get_env(:ex_cldr, :https_proxy) || | ||
System.get_env("HTTPS_PROXY") || | ||
System.get_env("https_proxy") | ||
end | ||
|
||
def otp_version do | ||
:erlang.system_info(:otp_release) |> List.to_integer | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this line seems to be problematic, failing to compile (elixir-cldr/cldr#201 (comment)) when https_proxy
is not setset to an empty string.