Skip to content
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

Installable request/response phase handlers #128

Open
jonathanstowe opened this issue Nov 28, 2015 · 0 comments
Open

Installable request/response phase handlers #128

jonathanstowe opened this issue Nov 28, 2015 · 0 comments

Comments

@jonathanstowe
Copy link
Collaborator

Hi,
Perl 5's LWP::UserAgent has an add_handler()/remove_handler() methods that allow you to specify a sub-routine that will be run (with the request or response object as arguments,) at various phases of the HTTP conversation, thus allowing the user code to respond in a different way to the core code or to alter the request or response in a specific way depending on the circumstances.

A very specific use case for this is the way that redirects are handled, currently we simply build a new request based on the original one with the new location and so forth and then re-request that, however in https://github.com/jonathanstowe/WebService-Soundcloud the "download" will require a redirect to Amazon cloud storage which gets immensely confused by all the headers that have been added for the soundcloud authorization and stuff, so ideally there would be a "redirect request" handler that got control of the new request before it is made to remove all the inappropriate headers.

Other places this would be useful would be in responses suggesting authorisation is required, (a handler could find the auhorisation tokens and make a new request,) or in handling specific response codes in a certain way transparently.

Internally this may also enable us to make the code even more modular (i.e. there are default phase handlers,) and flexible.

I haven't any firm plans for the actual implementation of this as yet but welcome any and all input :)

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

No branches or pull requests

1 participant