Skip Menu |

This queue is for tickets about the Net-Async-WebSocket CPAN distribution.

Report information
The Basics
Id: 124118
Status: resolved
Priority: 0/
Queue: Net-Async-WebSocket

People
Owner: Nobody in particular
Requestors: michael [...] mcclimon.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.13



Subject: Allow passing a request object to use during handshake
Date: Wed, 17 Jan 2018 13:58:53 -0500
To: bug-Net-Async-WebSocket [...] rt.cpan.org
From: Michael McClimon <michael [...] mcclimon.org>
In testing, I would really like to be able to pass in some cookies to use for the initial client handshake. This isn't currently possible without some hacking inside the guts of the client class, but would be possible if the client accepted a `req` key, which is implemented in the attached patch. With this patch, you can do something like the following: my $req = Protocol::WebSocket::Request->new; $req->cookies('key=val'); my $client = Net::Async::WebSocket::Client->new( ... ); $client->connect( host => $host, service => $service, req => $req, ); Thanks! Michael, with a hat tip to Matthew Horsfall (alh) -- Michael McClimon michael@mcclimon.org

Message body is not shown because sender requested not to inline it.

Now released in 0.13 -- Paul Evans
Subject: rt124118.patch
=== modified file 'lib/Net/Async/WebSocket/Client.pm' --- lib/Net/Async/WebSocket/Client.pm 2017-12-08 17:52:31 +0000 +++ lib/Net/Async/WebSocket/Client.pm 2018-10-11 17:52:32 +0000 @@ -103,6 +103,7 @@ my $hs = Protocol::WebSocket::Handshake::Client->new( url => $params{url}, + req => $params{req}, ); $self->debug_printf( "HANDSHAKE start" ); @@ -140,6 +141,11 @@ URL to provide to WebSocket handshake. This is also used to infer the host and service name (port number) if not otherwise supplied. +=item req => Protocol::WebSocket::Request + +Optional. If provided, gives the L<Protocol::WebSocket::Request> instance used +for performing the handshake. + =back The returned L<Future> returns the client instance itself, making it useful === modified file 't/01client.t' --- t/01client.t 2017-12-08 17:48:47 +0000 +++ t/01client.t 2018-10-11 17:52:32 +0000 @@ -135,4 +135,24 @@ is( $bytes, $UTF_8_bytes, 'content of binary frame' ); } +# custom req +{ + my $client = Net::Async::WebSocket::Client->new(); + $loop->add( $client ); + + my $f = $client->connect_handle( $clientsock, + url => "ws://localhost/test", + req => Protocol::WebSocket::Request->new( headers => [ "X-Custom" => "value" ] ), + ); + $f->on_fail( sub { $f->get } ); + + my $h = Protocol::WebSocket::Handshake::Server->new; + + my $stream = ""; + wait_for_stream { $h->parse( $stream ); $stream = ""; $h->is_done } $serversock => $stream; + + is( $h->req->field( "X-Custom" ), "value", + 'request header contains custom field' ); +} + done_testing;