Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Add support for middlewares / plugins #5

Open
almet opened this issue Oct 24, 2012 · 10 comments
Open

Add support for middlewares / plugins #5

almet opened this issue Oct 24, 2012 · 10 comments

Comments

@almet
Copy link
Member

almet commented Oct 24, 2012

And activate some of them by default.

For instance, that would be useful to have more than one service url, and to fallback to the other ones if the fist one fails.

Some code for that is implemented in https://github.com/mozilla-services/queuey-py/blob/master/queuey_py/client.py

@Natim
Copy link
Member

Natim commented Oct 24, 2012

Yes, I am thinking of a HeaderContext that would prepare the header and data of a request.

from respire.context_processors.http_auth import HttpAuth
SPORE_CONTEXT_PROCESSORS = (HttpAuth(username='x', password='ducksboard_key'), )

client_from_url('SPORE_URL', HeaderContext())

HeaderContext should have a update method that will get a self.headers and self.data and return them after having added necessarily information.

@almet
Copy link
Member Author

almet commented Oct 24, 2012

I don't get why we should name that differently than a middleware, to be honnest. I don't think either "header" or "context" are right. "processors", why not.

"Middleware" has the advantage of exposing clearly that it does something before the request is given to us, and after. "decorator" could be another name.

If we're using requests, we could probably attach some information to the request/response objects on the fly, and that could be enough, no?

@Natim
Copy link
Member

Natim commented Oct 24, 2012

How do you create a request before to send it with requests?

@Natim
Copy link
Member

Natim commented Oct 24, 2012

Your description would be a middleware.
How can you pass your request through middleware before to actually send
the request using requests?

2012/10/24 Alexis Metaireau [email protected]

I don't get why we should name that differently than a middleware, to be
honnest. I don't think either "header" or "context" are right.
"processors", why not.

"Middleware" has the advantage of exposing clearly that it does something
before the request is given to us, and after. "decorator" could be another
name.

If we're using requests, we could probably attach some information to the
request/response objects on the fly, and that could be enough, no?


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-9740612.

@almet
Copy link
Member Author

almet commented Oct 24, 2012

That's a middleware: that does something like that:

client → middlware(request) → requests → middleware(response) → client

@almet
Copy link
Member Author

almet commented Oct 24, 2012

(we need to use the requests internal objects)

@Natim
Copy link
Member

Natim commented Oct 24, 2012

I thought with a context_processor we would be able to do it without hacking on requests.

@Natim
Copy link
Member

Natim commented Oct 24, 2012

We can also make a RespireRequest object and then use the call method to actually send the request.

@almet
Copy link
Member Author

almet commented Oct 24, 2012

hmm, I see the reasoning now. I find it kind of weird to control the arguments we pass to the request lib, but that makes some sense. We need to dig into requests internal to see what makes more sense.

@almet
Copy link
Member Author

almet commented Oct 24, 2012

after digging a bit more in the codebase, it seems that having our own request object which will do the call to requests makes more sense.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants