AnyEvent-WebSocket-Server

 view release on metacpan or  search on metacpan

lib/AnyEvent/WebSocket/Server.pm  view on Meta::CPAN

The argument C<$default_response> is a L<Protocol::WebSocket::Response> valid for the given C<$request>.
If you don't need to manipulate the response, just return C<$default_response>. That is,

    handshake => sub { $_[1] }

is the minimal valid code for C<handshake>.

In addition to C<$response>, you can return C<@other_results> if you want.
Those C<@other_results> can be obtained later from the condition variable of C<establish()> method.

If you throw an exception from C<$handshake> code, we think you reject the C<$request>.
In this case, the condition variable of C<establish()> method croaks.


=item C<validator> => CODE (optional)

B<< This option is only for backward compatibility. Use C<handshake> option instead. If C<handshake> option is specified, this option is ignored. >>

A subroutine reference to validate the incoming WebSocket request.
If omitted, it accepts the request.

The validator is called like

    @other_results = $validator->($request)

where C<$request> is a L<Protocol::WebSocket::Request> object.

If you reject the C<$request>, throw an exception.

If you accept the C<$request>, don't throw any exception.
The return values of the C<$validator> are sent to the condition variable of C<establish()> method.

=item C<ssl_key_file> => FILE_PATH (optional)

A string of the filepath to the SSL/TLS private key file in PEM format.
If you set this option, you have to set C<ssl_cert_file> option, too.

If this option or C<ssl_cert_file> option is set, L<AnyEvent::WebSocket::Server> encrypts the WebSocket streams with SSL/TLS.

=item C<ssl_cert_file> => FILE_PATH (optional)

t/handshake.t  view on Meta::CPAN

        my $port = start_passive_server($s, sub { $finish_cv->send })->recv;
        my $raw_res = get_raw_response($cconfig, $port, "/foobar")->recv;
        $finish_cv->recv;
        note("Response:");
        note($raw_res);
        is $raw_res, $input_response, "raw response OK";
    });
};

handshake_error_case(
    label => "throw exception",
    handshake => sub { die "BOOM!" },
    exp_error_pattern => qr/BOOM\!/,
);

handshake_error_case(
    label => "no return",
    handshake => sub { return () },
    exp_error_pattern => qr/handshake response was undef/i,
);

t/tls_error.t  view on Meta::CPAN

    my $port = $port_cv->recv;
    my $client_conn_cv = AnyEvent::WebSocket::Client->new($cconfig->client_args)->connect($cconfig->connect_url($port, "/websocket"));
    my $client_ret = try {
        $client_conn_cv->recv;
        undef;
    }catch {
        my ($e) = @_;
        $e;
    };
    my $server_conn_error = $server_conn_cv->recv;
    isnt $server_conn_error, undef, "server conn should throw exception";
    note("server_conn_error was:");
    note($server_conn_error);
    note("client_conn_cv returned this:");
    note(defined($client_ret) ? $client_ret : "<undef>");
});

done_testing;

xt/js/browser.html  view on Meta::CPAN

    <div id="qunit-fixture"></div>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script>
"use strict";

function getPort() {
    return 18888;
    // var port_re = new RegExp("port=([0-9]+)");
    // if(!port_re.test(document.location)) {
    //     throw "cannot obtain port number";
    // }
    // return parseInt(port_re.$1, 10);
}

function createData(base, iteration_num) {
    var data = "";
    for(var i = 0 ; i < iteration_num ; i++) {
        data += base;
    }
    return data;



( run in 0.328 second using v1.01-cache-2.11-cpan-496ff517765 )