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

Request: PSGI protocol for HTTP::Tiny #130

Closed
djzort opened this issue Sep 26, 2019 · 5 comments
Closed

Request: PSGI protocol for HTTP::Tiny #130

djzort opened this issue Sep 26, 2019 · 5 comments

Comments

@djzort
Copy link

djzort commented Sep 26, 2019

The https://metacpan.org/pod/LWP::Protocol::PSGI module allows you to provide code that will called to respond to requests you make with LWP, rather than them going off to a server. The https://metacpan.org/pod/Furl::PSGI module does the same for the Furl library.

Something analogous, but for HTTP::Tiny, would be an amazing addition. The outcome would be vastly easier testing.

The pod of LWP::Protocol::PSGI has a good example, where a trivial dancer app is loaded to respond to LWP requests to google.com. In a test file, an author can mock a web service without having to start up a http daemon of some sort, and doesnt need to insert shims in their code either. Another example from the real world is https://metacpan.org/source/HAKOBE/WebService-SyoboiCalendar-0.02/t/lib/SyobocalMock.pm. The code being tested in entirely unaware of the subterfuge.

A version for HTTP::Tiny would do something very similar. Authors of code using HTTP::Tiny could use this new HTTP::Tiny w/ PSGI in their test suites to mock web services they want to test against.

LWP is multiprotocol, so lends itself to having PSGI added. For HTTP::Tiny to speak to something via PSGI, the code would need to do something like:

  • Fake HTTP::Tiny entirely, with a module that would be loaded prior to HTTP::Tiny and trick perl in to not loading it. For example:

use HTTP::Tiny::FakeViaPSGI; # This fakes the HTTP::Tiny namespace
use HTTP::Tiny; # This then does nothing other than call HTTP::Tiny->import, as %INC already contains an entry for HTTP::Tiny

  • Add hooks in HTTP::Tiny, so that PSGI can be used
  • Other, as suggested by more creative Perl people
@djzort
Copy link
Author

djzort commented Sep 26, 2019

See also perl-foundation-outreach/ideas#34

@karenetheridge
Copy link
Contributor

I would fear HTTP::Tiny not being so tiny anymore. Is it possible to do this with a subclass?

@djzort
Copy link
Author

djzort commented Sep 26, 2019

My intention is to avoid suggesting the implementation details in the request, as this may distract people from supporting the outcome.

For comparison sake, LWP has pluggable protocols. Furl::PSGI subclasses Furl and replaces key functions. Another approach may be via Class::Method::Modifiers whos maintainer I hear is a cool person.

@xdg
Copy link
Collaborator

xdg commented Jul 20, 2021

This is outside the scope of HTTP::Tiny.

@xdg xdg closed this as completed Jul 20, 2021
@karenetheridge
Copy link
Contributor

This is outside the scope of HTTP::Tiny.

..but perhaps worth exploring in a role or subclass.

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

3 participants