AnyEvent-WebSocket-Client

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

  - Fixed a testing bug that was reportd on Debian Buster.

0.49      2018-07-09 21:06:24 -0400
  - Fixed a bug where adding next_message callback within a next_message
    callback was called immediately with the same message (gh#39 xavery++)

0.48      2018-05-21 21:08:49 -0400
  - Production version functionally identical to the 0.47_01 release.

0.47_01   2018-05-20 09:35:23 -0400
  - Add max_fragments attribute ot AnyEvent::WebSocket::Client
  - Add max_fragments attribute ot AnyEvent::WebSocket::Connection

0.46      2018-04-07 16:39:29 -0400
  - Production version functionally identical to the 0.45_01 release.

0.45_01   2018-04-04 17:01:03 -0400
  - add env_proxy property to AnyEvent::WebSocket::Client (gh#36 gh#37 TOSHIOITO++)

0.44      2017-12-12 15:37:51 -0500
  - Compatibility with 0.22.

README  view on Meta::CPAN

     X-Baz: abc
     X-Baz: def

    Although, the order cannot be guaranteed when using the hash style.

 max_payload_size

    The maximum payload size for received frames. Currently defaults to
    whatever Protocol::WebSocket defaults to.

 max_fragments

    The maximum number of fragments for received frames. Currently defaults
    to whatever Protocol::WebSocket defaults to.

 env_proxy

    If you set true to this boolean attribute, it loads proxy settings from
    environment variables. If it finds valid proxy settings, connect method
    will use that proxy.

    Default: false.

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

    };
  },
);


has max_payload_size => (
  is => 'ro',
);


has max_fragments => (
  is => 'ro',
);


has env_proxy => (
  is => 'ro',
  default => sub { 0 },
);


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

            $done->croak("no subprotocol in response");
          }
        }
        undef $handshake;
        $done->send(
          AnyEvent::WebSocket::Connection->new(
                  handle               => $hdl,
                  masked               => 1,
            maybe subprotocol          => $sb,
            maybe max_payload_size     => $self->max_payload_size,
            maybe max_fragments        => $self->max_fragments,
          )
        );
        undef $hdl;
        undef $done;
      }
    });
  }, sub { $self->timeout });
  $done;
}

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

 X-Baz: abc
 X-Baz: def

Although, the order cannot be guaranteed when using the hash style.

=head2 max_payload_size

The maximum payload size for received frames.  Currently defaults to whatever
L<Protocol::WebSocket> defaults to.

=head2 max_fragments

The maximum number of fragments for received frames.  Currently defaults to whatever
L<Protocol::WebSocket> defaults to.

=head2 env_proxy

If you set true to this boolean attribute, it loads proxy settings
from environment variables. If it finds valid proxy settings,
C<connect> method will use that proxy.

Default: false.

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

has subprotocol => (
  is => 'ro',
);


has max_payload_size => (
  is => 'ro',
);


has max_fragments => (
  is => 'ro',
);


has close_code => (
  is => 'rw',
);


has close_reason => (

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

    $self->_is_read_open(0);
    $self->_is_write_open(0);
    $self->close_error($message) if defined $message;
    $_->($self, $message) for @{ $self->_finish_cb };
  };
  $self->handle->on_error($finish);
  $self->handle->on_eof($finish);

  my $frame = Protocol::WebSocket::Frame->new(
    maybe max_payload_size => $self->max_payload_size,
    maybe max_fragments_amount => $self->max_fragments,
  );

  my $read_cb = sub {
    my ($handle) = @_;
    local $@;
    my $strong_self = $self; # preserve $self because otherwise $self can be destroyed in the callbacks
    my $success = eval
    {
      $frame->append($handle->{rbuf});
      while(defined(my $body = $frame->next_bytes))

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

=head2 subprotocol

The subprotocol returned by the server.  If no subprotocol was requested, it
may be C<undef>.

=head2 max_payload_size

The maximum payload size for received frames.  Currently defaults to whatever
L<Protocol::WebSocket> defaults to.

=head2 max_fragments

The maximum number of fragments for received frames.  Currently defaults to whatever
L<Protocol::WebSocket> defaults to.

=head2 close_code

If provided by the other side, the code that was provided when the
connection was closed.

=head2 close_reason

If provided by the other side, the reason for closing the connection.

t/anyevent_websocket_connection.t  view on Meta::CPAN

        undef $w;
        $handle->push_write("A" x 256);
      });
    });
    $cv_finish->recv;

    is scalar(@received_messages), 0, "the frame is too huge to receive.";
  };


  subtest "Connection should refuse messages with too many fragments", sub {
    my ($x_conn, $y_handle) = create_connection_and_handle;
    my $cv_finish = AnyEvent->condvar;
    $cv_finish->begin;
    $cv_finish->begin;
    my @received_messages = ();
    $x_conn->on(finish => sub {
      $cv_finish->end;
    });
    $x_conn->on(each_message => sub {
      push(@received_messages, $_[1])

t/anyevent_websocket_connection.t  view on Meta::CPAN

        $cv_finish->send;
        return;
      }
      my $w; $w = AnyEvent->idle(cb => sub {
        undef $w;
        $handle->push_write(Protocol::WebSocket::Frame->new(fin => 0, opcode => 0, buffer => "A")->to_bytes);
      });
    });
    $cv_finish->recv;

    is scalar(@received_messages), 0, "the message consists of too many fragments to receive.";
  };
};

subtest 'other end is closed' => sub {

  my($x,$y) = create_connection_pair;

  my $round_trip = sub {

    my($message) = @_;



( run in 0.597 second using v1.01-cache-2.11-cpan-b16cb0d3907 )