Skip to content

Commit

Permalink
Merge pull request #424 from vereis/master
Browse files Browse the repository at this point in the history
HTTPoison.AsyncResponse id's can be {:maybe_redirect_response, status, headers, client}
  • Loading branch information
edgurgel authored Oct 17, 2020
2 parents 19f04da + f2d5381 commit 40580cd
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 63 deletions.
27 changes: 26 additions & 1 deletion lib/httpoison.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ defmodule HTTPoison.Request do
* `:socks5_user`- socks5 username
* `:socks5_pass`- socks5 password
* `:ssl` - SSL options supported by the `ssl` erlang module
* `:follow_redirect` - a boolean that causes redirects to be followed
* `:follow_redirect` - a boolean that causes redirects to be followed, can cause a request to return
a `MaybeRedirect` struct. See: HTTPoison.MaybeRedirect
* `:max_redirect` - an integer denoting the maximum number of redirects to follow. Default is 5
* `:params` - an enumerable consisting of two-item tuples that will be appended to the url as query string parameters
* `:max_body_length` - a non-negative integer denoting the max response body length. See :hackney.body/2
Expand Down Expand Up @@ -95,6 +96,30 @@ defmodule HTTPoison.AsyncEnd do
@type t :: %__MODULE__{id: reference}
end

defmodule HTTPoison.MaybeRedirect do
@moduledoc """
If the option `:follow_redirect` is given to a request, HTTP redirects are automatically follow if
the method is set to `:get` or `:head` and the response's `status_code` is `301`, `302` or `307`.
If the method is set to `:post`, then the only `status_code` that get's automatically
followed is `303`.
If any other method or `status_code` is returned, then this struct is returned in place of a
`HTTPoison.Response` or `HTTPoison.AsyncResponse`, containing the `redirect_url` to allow you
to optionally re-request with the method set to `:get`.
"""

defstruct status_code: nil, request_url: nil, request: nil, redirect_url: nil, headers: []

@type t :: %__MODULE__{
status_code: integer,
headers: list,
request: HTTPoison.Request.t(),
request_url: HTTPoison.Request.url(),
redirect_url: HTTPoison.Request.url()
}
end

defmodule HTTPoison.Error do
defexception reason: nil, id: nil
@type t :: %__MODULE__{id: reference | nil, reason: any}
Expand Down
Loading

0 comments on commit 40580cd

Please sign in to comment.