X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FPlack%2FApp%2FProxy%2FWebSocket.pm;h=25f5a15c257065471b8c55994014d18f57451589;hb=HEAD;hp=770bae8cfdc0d9a8b8a520b6bd1d96aa244ca617;hpb=b974736ef87a248b8caa11276de5e4b7fc5e3833;p=chaz%2Fp5-Plack-App-Proxy-WebSocket diff --git a/lib/Plack/App/Proxy/WebSocket.pm b/lib/Plack/App/Proxy/WebSocket.pm index 770bae8..25f5a15 100644 --- a/lib/Plack/App/Proxy/WebSocket.pm +++ b/lib/Plack/App/Proxy/WebSocket.pm @@ -8,7 +8,7 @@ use AnyEvent::Handle; use AnyEvent::Socket; use HTTP::Headers; use HTTP::Request; -use HTTP::Parser::XS qw/parse_http_response HEADERS_AS_ARRAYREF/; +use HTTP::Parser::XS qw/parse_http_response HEADERS_AS_HASHREF/; use Plack::Request; use URI; @@ -28,22 +28,24 @@ use parent 'Plack::App::Proxy'; =head1 DESCRIPTION -This is a subclass of L that adds support for proxying -WebSocket connections. It works by looking for the C header, -forwarding the handshake to the remote back-end, and then buffering -full-duplex between the client and the remote. Regular HTTP requests are -handled by L as usual, though there are a few differences -related to the generation of headers for the back-end request; see -L for details. +This is a subclass of L that adds support for transparent +(i.e. reverse) proxying WebSocket connections. If your proxy is a forward +proxy that is to be explicitly configured in the system or browser, you may be +able to use L instead. + +This module works by looking for the C header, completing +the handshake with the remote, and then buffering full-duplex between the +client and the remote. Regular requests are handled by L +as usual, though there are a few differences related to the generation of +headers for the back-end request; see L for details. This module has no configuration options beyond what L 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 note -that extra L server features are required in order for the WebSocket -proxying to work. The server must support C and C. -It is also highly recommended that you choose a C server, -though that isn't strictly required. L is one good choice for this -application. +documentation of that module for advanced usage not covered here. Also, you +must use a L server that supports C and C. +For performance reasons, you should also use a C server +(like L) and the L user +agent back-end (which is the default, so no extra configuration is needed). This module is B. I use it in development and it works swimmingly for me, but it is completely untested in production scenarios. @@ -119,11 +121,11 @@ sub call { $buffer .= $buf; my ($ret, $http_version, $status, $message, $headers) = - parse_http_response($buffer, HEADERS_AS_ARRAYREF); + parse_http_response($buffer, HEADERS_AS_HASHREF); $server->push_shutdown if $ret == -2; return if $ret < 0; - $headers = [$self->response_headers($headers)] unless $status == 101; + $headers = [$self->response_headers(HTTP::Headers->new(%$headers))] unless $status == 101; $writer = $res->([$status, $headers]); $writer->write(substr($buffer, $ret)); $buffer = undef;