-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] Allow adapter specific data to be stored inside Tesla.Env #48
Comments
While I do get the idea you could use `Tesla.put_opt(:location, ...)` and
then access the value with `env.opts.location`.
Is there a reason why opts might not be a good solution?
…On Wed, 25 Jan 2017 at 01:38, Tobiasz Małecki ***@***.***> wrote:
Example:
#little change to adapter
defmodule Tesla.Adapter.Hackney do
def call(env, opts) do
with {:ok, status, headers, body, location} <- request(env, opts || []) do
%{env | status: status,
headers: headers,
body: body,
private: %{final_location: location}}
end
end
defp handle({:ok, status, headers, ref}) do
with location <> "" <- :hackney.location(ref),
{:ok, body} <- :hackney.body(ref) do
{:ok, status, headers, body, location}
end
end
end
#usage
iex(1)> Tesla.get("https://github.com/teamon/tesla", opts: [follow_redirect: true])
%Tesla.Env{
url: "https://github.com/teamon/tesla",
private: %{final_location: "https://github.com/teamon/tesla"}
}
iex(2)> Tesla.get("https://goo.gl/8hfJ7F", opts: [follow_redirect: true])
%Tesla.Env{
url: "https://goo.gl/8hfJ7F",
private: %{final_location: "https://github.com/teamon/tesla"}
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#48>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAfk8tV-nq-xqoqvo6hb-R7Vmlb66e3ks5rVplqgaJpZM4Ls93b>
.
|
Sure, opts could be used, but I think it's would be cleaner to not mix different entities under same key. For me When you do #some pseudocode to make this 100% clear
important_in_request = [follow_redirect: true]
ignored_by_tesla = [random_key: :value]
%Tesla.Env{
opts: _user_probably_dont_care,
private: additional_data_that_user_may_be_interested_in
} = Tesla.get(url, opts: important_in_request, private: ignored_by_tesla) |
I agree mixing opts with private might not be a good idea. One question remains - what should be the desired adapter's behaviour and rules for using private properties? (Assuming client code does not modify adapters) In case of "follow redirects" I think this should be a tesla middleware like this |
My first idea for private properties can be described as "allow to store anything useful, don't merge to master anything that tries to read from it". I'll think about it more later, but unfortunately I'm little busy at the moment. about FollowRedirects middleware btw I made middleware for data compression |
@amatalai sooooo, what are we doing with this? ;) |
I wish I could create PR with some proposal to push work on this forward, but lately I don't have time to do that. |
I need to revisit this idea. With ability to add middleware before adapter it should be easy to save raw headers etc with simple middleware and without any breaking changes. |
As mentioned in #104 there was always a possibility to add something right around adapter :) |
Please see possible solution in #37 |
Yeah, this wouldn't be useful at the moment |
Example:
The text was updated successfully, but these errors were encountered: