Giter Site home page Giter Site logo

Comments (10)

teamon avatar teamon commented on May 6, 2024

from tesla.

amatalai avatar amatalai commented on May 6, 2024

Sure, opts could be used, but I think it's would be cleaner to not mix different entities under same key.

For me :opts is write-only for user and read-only for Tesla when :private will be opposite.
What do I mean by this?

When you do Tesla.get(url, opts: [something: true]) you probably don't care about what's saved under :opts key in response, because you know what you have passed in function call. On the other hand Tesla shouldn't use data from :private when making request, because this field would allow to store inconsistent data(specific to one adapter/middleware), which from end user perspective may be useful.

#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)

from tesla.

teamon avatar teamon commented on May 6, 2024

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

from tesla.

amatalai avatar amatalai commented on May 6, 2024

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
I like this, it will allow me to remove custom implementation from my library
one note: httpc default for autoredirect is true, you should probably disable it inside this middleware

btw I made middleware for data compression
https://github.com/amatalai/link_preview/blob/1.0.0/lib/compression_middleware.ex
It's work in progress now, but I think that I'll have time to finish it in next few days (I'll make separate issue tomorrow to discuss details)

from tesla.

teamon avatar teamon commented on May 6, 2024

@amatalai sooooo, what are we doing with this? ;)

from tesla.

amatalai avatar amatalai commented on May 6, 2024

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.

from tesla.

amatalai avatar amatalai commented on May 6, 2024

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.

from tesla.

teamon avatar teamon commented on May 6, 2024

As mentioned in #104 there was always a possibility to add something right around adapter :)

from tesla.

teamon avatar teamon commented on May 6, 2024

Please see possible solution in #37

from tesla.

amatalai avatar amatalai commented on May 6, 2024

Yeah, this wouldn't be useful at the moment

from tesla.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.