NAME

Langertha::Request::SyncHTTP - Synchronous LWP-backed HTTP client satisfying the async do_request contract

VERSION

version 0.503

user_agent

The synchronous HTTP client used to run the request, normally an LWP::UserAgent. Any object with a ->request($http_request [, $content_cb]) method that returns an HTTP::Response satisfies the contract. Required.

do_request

my $future = $client->do_request( request => $http_request );

my $future = $client->do_request(
  request   => $http_request,
  on_header => sub {
    my ($response) = @_;
    return sub { my ($data) = @_; ... };   # per-chunk, undef at end
  },
);

Runs $http_request synchronously through "user_agent" and returns an already-complete Future resolving to the HTTP::Response. No event loop is involved: because the future is already ready, any await on it (or ->get) resolves immediately, so the whole _f chain runs synchronously and sequentially.

When an on_header callback is given the request streams: LWP::UserAgent's per-chunk content callback is bridged to the contract — on_header is called once with the HTTP::Response (headers) and returns a chunk-sub, which then receives each body chunk as LWP reads it from the socket and finally undef once to signal end-of-body. Delivery is incremental (the first chunk reaches the caller before the body has finished arriving, so time-to-first-token is real) but blocking: the calling thread waits inside the request until the stream ends.

LWP runs the content callback only for a successful response. For a non-success status, and for an LWP-internal error response (connection refused, DNS failure, timeout), the shim still calls on_header once with the response and hands the chunk-sub the accumulated body, then undef — the same sequence Net::Async::HTTP produces, so the caller's $response->is_success check fires the same way on both backends.

If the chunk-sub (or on_header) dies, or LWP aborts reading the body mid-stream (recorded in its X-Died header), the returned future fails with that exception and no undef end signal is sent: a truncated stream is never resolved as a success.

This is the drop-in fallback backend for the async do_request contract (Langertha::Role::AsyncHTTP): HTTP error statuses (4xx/5xx) resolve with the response — they do not fail the future — so the caller checks $response->is_success, exactly as with Net::Async::HTTP.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.