| 1 | package Langertha::Skeid::Proxy::RelayContent; | ||
| 2 | 47 | our $VERSION = '0.003'; | |
| 3 | # ABSTRACT: Upstream response content that is always relayed as raw bytes | ||
| 4 | 47 | ▶ | use Mojo::Base 'Mojo::Content::Single'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | |||
| 7 | 63 | ▶ | sub is_sse {0} |
|
Subroutine
is_sse: called CC=1 SCAR=0.0
Pod
documented
| |||
| 8 | |||
| 9 | |||
| 10 | 47 | 1; | |
| 11 | |||
| 12 | __END__ | ||
| 13 | |||
| 14 | =pod | ||
| 15 | |||
| 16 | =encoding UTF-8 | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | Langertha::Skeid::Proxy::RelayContent - Upstream response content that is always relayed as raw bytes | ||
| 21 | |||
| 22 | =head1 VERSION | ||
| 23 | |||
| 24 | version 0.003 | ||
| 25 | |||
| 26 | =head1 DESCRIPTION | ||
| 27 | |||
| 28 | The content object the proxy puts on a streaming upstream response before starting it: a | ||
| 29 | L<Mojo::Content::Single> that never takes Mojolicious's own Server-Sent Events path. | ||
| 30 | |||
| 31 | Mojolicious parses a response body itself when its C<Content-Type> is exactly | ||
| 32 | C<text/event-stream> (no parameters) and the body is not chunked: the bytes become C<sse> events | ||
| 33 | and no C<read> event is ever emitted. The relay reads the upstream on C<read>, so such an | ||
| 34 | upstream would be relayed as nothing and metered as a served request without tokens. Skeid | ||
| 35 | reads the SSE frames itself and relays them byte for byte, so it needs the bytes whatever the | ||
| 36 | exact media type or framing. | ||
| 37 | |||
| 38 | my $tx = $ua->build_tx(POST => $url, \%headers, json => $body); | ||
| 39 | $tx->res->content(Langertha::Skeid::Proxy::RelayContent->new); | ||
| 40 | $tx->res->content->unsubscribe('read')->on(read => sub { ... }); | ||
| 41 | |||
| 42 | =head2 is_sse | ||
| 43 | |||
| 44 | Always false, so the body is parsed as plain content and every byte arrives on C<read>. | ||
| 45 | |||
| 46 | =head1 SEE ALSO | ||
| 47 | |||
| 48 | L<Langertha::Skeid::Proxy>, L<Mojo::Content::Single> | ||
| 49 | |||
| 50 | =head1 SUPPORT | ||
| 51 | |||
| 52 | =head2 Issues | ||
| 53 | |||
| 54 | Please report bugs and feature requests on GitHub at | ||
| 55 | L<https://github.com/Getty/langertha-skeid/issues>. | ||
| 56 | |||
| 57 | =head2 IRC | ||
| 58 | |||
| 59 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||
| 60 | |||
| 61 | =head1 CONTRIBUTING | ||
| 62 | |||
| 63 | Contributions are welcome! Please fork the repository and submit a pull request. | ||
| 64 | |||
| 65 | =head1 AUTHOR | ||
| 66 | |||
| 67 | Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/> | ||
| 68 | |||
| 69 | =head1 COPYRIGHT AND LICENSE | ||
| 70 | |||
| 71 | This software is copyright (c) 2026 by Torsten Raudssus. | ||
| 72 | |||
| 73 | This is free software; you can redistribute it and/or modify it under | ||
| 74 | the same terms as the Perl 5 programming language system itself. | ||
| 75 | |||
| 76 | =cut | ||