Plack-App-Proxy-WebSocket

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    This module works by looking for the Upgrade: WebSocket header,
    completing the handshake with the remote, and then buffering
    full-duplex between the client and the remote. Regular requests are
    handled by Plack::App::Proxy as usual, though there are a few
    differences related to the generation of headers for the back-end
    request; see "build_headers_from_env" for details.

    This module has no configuration options beyond what Plack::App::Proxy
    requires or provides, so it may be an easy drop-in replacement. Read
    the documentation of that module for advanced usage not covered here.
    Also, you must use a PSGI server that supports psgi.streaming and
    psgix.io. For performance reasons, you should also use a
    psgi.nonblocking server (like Twiggy) and the
    Plack::App::Proxy::Backend::AnyEvent::HTTP user agent back-end (which
    is the default, so no extra configuration is needed).

    This module is EXPERIMENTAL. I use it in development and it works
    swimmingly for me, but it is completely untested in production
    scenarios.

METHODS

lib/Plack/App/Proxy/WebSocket.pm  view on Meta::CPAN

our $VERSION = '0.04'; # VERSION


sub call {
    my ($self, $env) = @_;
    my $req = Plack::Request->new($env);

    # detect a protocol upgrade handshake or just proxy as usual
    my $upgrade = $req->header('Upgrade') or return $self->SUPER::call($env);

    $env->{'psgi.streaming'} or die "Plack server support for psgi.streaming is required";
    my $client_fh = $env->{'psgix.io'} or die "Plack server support for the psgix.io extension is required";

    my $url = $self->build_url_from_env($env) or return [502, [], ["Bad Gateway"]];
    my $uri = URI->new($url);

    sub {
        my $res = shift;

        # set up an event loop if the server is blocking
        my $cv;

lib/Plack/App/Proxy/WebSocket.pm  view on Meta::CPAN


This module works by looking for the C<Upgrade: WebSocket> header, completing
the handshake with the remote, and then buffering full-duplex between the
client and the remote.  Regular requests are handled by L<Plack::App::Proxy>
as usual, though there are a few differences related to the generation of
headers for the back-end request; see L</build_headers_from_env> for details.

This module has no configuration options beyond what L<Plack::App::Proxy>
requires or provides, so it may be an easy drop-in replacement.  Read the
documentation of that module for advanced usage not covered here.  Also, you
must use a L<PSGI> server that supports C<psgi.streaming> and C<psgix.io>.
For performance reasons, you should also use a C<psgi.nonblocking> server
(like L<Twiggy>) and the L<Plack::App::Proxy::Backend::AnyEvent::HTTP> user
agent back-end (which is the default, so no extra configuration is needed).

This module is B<EXPERIMENTAL>.  I use it in development and it works
swimmingly for me, but it is completely untested in production scenarios.

=head1 METHODS

=head2 build_headers_from_env



( run in 0.260 second using v1.01-cache-2.11-cpan-4d50c553e7e )