Skip to content

Commit

Permalink
Merge pull request #17 from gabrielgiordan/add-mint-client-opts
Browse files Browse the repository at this point in the history
Add default Mint HTTP client options
  • Loading branch information
mathieuprog authored Mar 24, 2023
2 parents 593487f + 4c20550 commit 1d6b2c4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.25.x

* Add custom options for default Mint HTTP client.
* Fix the bug that occurs when the maximum available year in an IANA rule exceeds
the limit set by the 'max' rule (happened for Palestine).

Expand All @@ -20,6 +21,7 @@
`:build_dst_periods_until_year`

* Add a mix task to download the IANA time zone data for a given version

## 0.22.x

* Add a mix task to download the IANA time zone data for a given version
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module can, by default, only operate on datetimes in the UTC time zone. Alternat
third-party libraries, such as `tz`, to bring in time zone support and deal with datetimes in other time zones than UTC.

The `tz` library relies on the [time zone database](https://data.iana.org/time-zones/tzdb/) maintained by
[IANA](https://www.iana.org). As of version 0.25.0, `tz` uses version **tzdata2023a** of the IANA time zone database.
[IANA](https://www.iana.org). As of version 0.25.1, `tz` uses version **tzdata2023a** of the IANA time zone database.

* [Installation and usage](#installation-and-usage)
* [Core principles](#core-principles)
Expand All @@ -32,7 +32,7 @@ Add `tz` for Elixir as a dependency in your `mix.exs` file:
```elixir
def deps do
[
{:tz, "~> 0.25.0"}
{:tz, "~> 0.25.1"}
]
end
```
Expand Down Expand Up @@ -173,11 +173,18 @@ defp deps do
[
{:castore, "~> 0.1"},
{:mint, "~> 1.4"},
{:tz, "~> 0.25.0"}
{:tz, "~> 0.25.1"}
]
end
```
You may also add custom [options](https://hexdocs.pm/mint/Mint.HTTP.html#connect/4-options) for the http client `mint`:
```elixir
config :tz, Tz.HTTP.Mint.HTTPClient,
proxy: {:http, proxy_host, proxy_port, []}
```
## Custom HTTP client
You may implement the `Tz.HTTP.HTTPClient` behaviour in order to use another HTTP client.
Expand Down
3 changes: 2 additions & 1 deletion lib/tz/compiler_runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ defmodule Tz.CompilerRunner do
:data_dir,
:iana_version,
:build_dst_periods_until_year,
:reject_periods_before_year
:reject_periods_before_year,
Tz.HTTP.Mint.HTTPClient
]

unknown_env_keys =
Expand Down
4 changes: 3 additions & 1 deletion lib/tz/http/mint/http_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ if Code.ensure_loaded?(Mint.HTTP) do

@impl Tz.HTTP.HTTPClient
def request(hostname, path) do
{:ok, conn} = HTTP.connect(:https, hostname, 443)
opts = Application.get_env(:tz, Tz.HTTP.Mint.HTTPClient, [])

{:ok, conn} = HTTP.connect(:https, hostname, 443, opts)
{:ok, conn, _} = HTTP.request(conn, "GET", path, [], nil)

{:ok, response = %MintHTTPResponse{}} = recv_response(conn)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Tz.MixProject do
use Mix.Project

@version "0.25.0"
@version "0.25.1"

def project do
[
Expand Down

0 comments on commit 1d6b2c4

Please sign in to comment.