Packages
req
0.4.3
0.6.3
0.6.2
0.6.1
0.6.0
0.5.18
0.5.17
0.5.16
0.5.15
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.2
0.2.1
0.2.0
0.1.2
0.1.1
0.1.0
Req is a batteries-included HTTP client for Elixir.
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
57 Versions
Jump to
Current section
57 Versions
Compare versions
5
files changed
+73
additions
-9
deletions
| @@ -1,5 +1,13 @@ | |
| 1 1 | # CHANGELOG |
| 2 2 | |
| 3 | + ## v0.4.3 (2023-09-13) |
| 4 | + |
| 5 | + * [`Req.new/1`]: Fix setting `:redact_auth` |
| 6 | + |
| 7 | + * [`Req.Request`]: Add `Req.Request.get_option_lazy/3` |
| 8 | + |
| 9 | + * [`Req.Request`]: Add `Req.Request.drop_options/2` |
| 10 | + |
| 3 11 | ## v0.4.2 (2023-09-04) |
| 4 12 | |
| 5 13 | * [`put_plug`]: Handle response streaming on Plug 1.15+. |
| @@ -731,16 +739,19 @@ See "Adapter" section in `Req.Request` module documentation for more information | |
| 731 739 | [`retry`]: https://hexdocs.pm/req/Req.Steps.html#retry/1 |
| 732 740 | [`run_finch`]: https://hexdocs.pm/req/Req.Steps.html#run_finch/1 |
| 733 741 | |
| 742 | + [`Req.new/1`]: https://hexdocs.pm/req/Req.html#new/1 |
| 734 743 | [`Req.request/2`]: https://hexdocs.pm/req/Req.html#request/2 |
| 735 744 | [`Req.update/2`]: https://hexdocs.pm/req/Req.html#update/2 |
| 736 745 | |
| 737 | - [`Req.Request`]: https://hexdocs.pm/req/Req.Request.html |
| 738 | - [`Req.Request.new/1`]: https://hexdocs.pm/req/Req.Request.html#new/1 |
| 739 | - [`Req.Request.run_request/1`]: https://hexdocs.pm/req/Req.Request.html#run_request/1 |
| 740 | - [`Req.Request.get_option/3`]: https://hexdocs.pm/req/Req.Request.html#get_option/3 |
| 741 | - [`Req.Request.fetch_option/2`]: https://hexdocs.pm/req/Req.Request.html#fetch_option/2 |
| 742 | - [`Req.Request.fetch_option!/2`]: https://hexdocs.pm/req/Req.Request.html#fetch_option!/2 |
| 743 | - [`Req.Request.delete_option/2`]: https://hexdocs.pm/req/Req.Request.html#delete_option/2 |
| 746 | + [`Req.Request`]: https://hexdocs.pm/req/Req.Request.html |
| 747 | + [`Req.Request.new/1`]: https://hexdocs.pm/req/Req.Request.html#new/1 |
| 748 | + [`Req.Request.run_request/1`]: https://hexdocs.pm/req/Req.Request.html#run_request/1 |
| 749 | + [`Req.Request.get_option/3`]: https://hexdocs.pm/req/Req.Request.html#get_option/3 |
| 750 | + [`Req.Request.get_option_lazy/2`]: https://hexdocs.pm/req/Req.Request.html#get_option_lazy/2 |
| 751 | + [`Req.Request.fetch_option/2`]: https://hexdocs.pm/req/Req.Request.html#fetch_option/2 |
| 752 | + [`Req.Request.fetch_option!/2`]: https://hexdocs.pm/req/Req.Request.html#fetch_option!/2 |
| 753 | + [`Req.Request.delete_option/2`]: https://hexdocs.pm/req/Req.Request.html#delete_option/2 |
| 754 | + [`Req.Request.drop_options/2`]: https://hexdocs.pm/req/Req.Request.html#drop_options/2 |
| 744 755 | [`Req.Request.update_private/4`]: https://hexdocs.pm/req/Req.Request.html#update_private/4 |
| 745 756 | |
| 746 757 | [`Req.Response`]: https://hexdocs.pm/req/Req.Response.html |
| @@ -2,7 +2,7 @@ | |
| 2 2 | [{<<"Changelog">>,<<"https://hexdocs.pm/req/changelog.html">>}, |
| 3 3 | {<<"GitHub">>,<<"https://github.com/wojtekmach/req">>}]}. |
| 4 4 | {<<"name">>,<<"req">>}. |
| 5 | - {<<"version">>,<<"0.4.2">>}. |
| 5 | + {<<"version">>,<<"0.4.3">>}. |
| 6 6 | {<<"description">>,<<"Req is a batteries-included HTTP client for Elixir.">>}. |
| 7 7 | {<<"elixir">>,<<"~> 1.13">>}. |
| 8 8 | {<<"app">>,<<"req">>}. |
| @@ -335,6 +335,7 @@ defmodule Req do | |
| 335 335 | :receive_timeout, |
| 336 336 | :pool_timeout, |
| 337 337 | :unix_socket, |
| 338 | + :redact_auth, |
| 338 339 | |
| 339 340 | # TODO: Remove on Req 1.0 |
| 340 341 | :output, |
| @@ -406,6 +406,11 @@ defmodule Req.Request do | |
| 406 406 | |> Keyword.validate!([:method, :url, :headers, :body, :adapter, :options]) |
| 407 407 | |> Keyword.update(:url, URI.new!(""), &URI.new!/1) |
| 408 408 | |> Keyword.update(:options, %{}, &Map.new/1) |
| 409 | + |> Keyword.update( |
| 410 | + :registered_options, |
| 411 | + MapSet.new([:redact_auth]), |
| 412 | + &MapSet.put(&1, :redact_auth) |
| 413 | + ) |
| 409 414 | |
| 410 415 | struct!(__MODULE__, options) |
| 411 416 | end |
| @@ -421,6 +426,11 @@ defmodule Req.Request do | |
| 421 426 | end) |
| 422 427 | end) |
| 423 428 | |> Keyword.update(:options, %{}, &Map.new/1) |
| 429 | + |> Keyword.update( |
| 430 | + :registered_options, |
| 431 | + MapSet.new([:redact_auth]), |
| 432 | + &MapSet.put(&1, :redact_auth) |
| 433 | + ) |
| 424 434 | |
| 425 435 | struct!(__MODULE__, options) |
| 426 436 | end |
| @@ -446,6 +456,31 @@ defmodule Req.Request do | |
| 446 456 | Map.get(request.options, key, default) |
| 447 457 | end |
| 448 458 | |
| 459 | + @doc """ |
| 460 | + Gets the value for the option `key`. |
| 461 | + |
| 462 | + This is useful if the default value is very expensive to calculate or generally |
| 463 | + difficult to setup and teardown again. |
| 464 | + |
| 465 | + See also `get_option/3`. |
| 466 | + |
| 467 | + ## Examples |
| 468 | + |
| 469 | + iex> req = Req.Request.new(options: [a: 1]) |
| 470 | + iex> fun = fn -> |
| 471 | + ...> # some expensive operation here |
| 472 | + ...> 42 |
| 473 | + ...> end |
| 474 | + iex> Req.Request.get_option_lazy(req, :a, fun) |
| 475 | + 1 |
| 476 | + iex> Req.Request.get_option_lazy(req, :b, fun) |
| 477 | + 42 |
| 478 | + """ |
| 479 | + @spec get_option_lazy(t(), atom(), (-> term())) :: term() |
| 480 | + def get_option_lazy(request, key, fun) when is_function(fun, 0) do |
| 481 | + Map.get_lazy(request.options, key, fun) |
| 482 | + end |
| 483 | + |
| 449 484 | @doc """ |
| 450 485 | Fetches the value for the option `key`. |
| 451 486 | |
| @@ -508,6 +543,23 @@ defmodule Req.Request do | |
| 508 543 | update_in(request.options, &Map.delete(&1, key)) |
| 509 544 | end |
| 510 545 | |
| 546 | + @doc """ |
| 547 | + Drops the given `keys` from options. |
| 548 | + |
| 549 | + ## Examples |
| 550 | + |
| 551 | + iex> req = Req.Request.new(options: [a: 1, b: 2, c: 3]) |
| 552 | + iex> req = Req.Request.drop_options(req, [:a, :b]) |
| 553 | + iex> Req.Request.get_option(req, :a) |
| 554 | + nil |
| 555 | + iex> Req.Request.get_option(req, :c) |
| 556 | + 3 |
| 557 | + """ |
| 558 | + @spec drop_options(t(), [atom()]) :: t() |
| 559 | + def drop_options(request, keys) when is_list(keys) do |
| 560 | + update_in(request.options, &Map.drop(&1, keys)) |
| 561 | + end |
| 562 | + |
| 511 563 | @doc """ |
| 512 564 | Gets the value for a specific private `key`. |
| 513 565 | """ |
| @@ -1,7 +1,7 @@ | |
| 1 1 | defmodule Req.MixProject do |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 | - @version "0.4.2" |
| 4 | + @version "0.4.3" |
| 5 5 | @source_url "https://github.com/wojtekmach/req" |
| 6 6 | |
| 7 7 | def project do |