0 seconds for example.
POST /csrf HTTP/1.1
Host: api.example.com
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate, br
Referer: https://example
&Digest::SHA::sha256 ) . ".$ts";
The API returns it in a custom HTTP response header and/or in a JSON reply, something like:
HTTP/1.1 200 OK
Date: Thu, 27 Apr 2023 10:21:38 GMT
Server: A
5, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json
{"token":"899106ee26933c654c33b0fac9adc93f2adad2c95ff30a4eeebe200fbfeafb6a.1682591199","code
ocket qw( :ws );
use parent qw( WebSocket );
use Encode;
use HTTP::Status ();
use JSON ();
use Nice::Try;
use Socket qw( IPPROTO_TCP TCP_NODELAY );
use URI;
use WebSock
e => $code,
message => $data,
status => $status,
};
}
$data = JSON->new->convert_blessed->relaxed->utf8->encode( $data );
my $resp = WebSocket::Response->new(
WebSocket Server
=head1 SYNOPSIS
use WebSocket::Server;
use JSON;
my $origin = 'http://localhost';
my $j = JSON->new->relaxed->convert_blessed;
my $ws = WebSocket::Server->new(
0, type => 'user', message => "Hello" };
my $json = $j->encode( $hash );
$conn->send_utf8( $json );
},
utf8 => sub
Socket::Frame> object and the payload data are passed as arguments to the event handler.
use JSON;
$ws->on_recv(sub
{
my( $frame, $payload ) = @_;
if( $frame->is_binary )
elsif( $frame->is_text )
{
# do something else
my $hash = JSON::decode_json( $payload );
}
});
Any fatal error occurring in the callback are caught using