Skip to content

Commit

Permalink
no custom sockets for now
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 26, 2015
1 parent 7894739 commit 1712764
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 82 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -11,6 +11,7 @@
Mojolicious::Validator::Validation.
- Removed multi-name support from param method in Mojo::Parameters.
- Removed multi-name support from cookie and upload methods in Mojo::Message.
- Removed custom socket support from Mojo::UserAgent.
- Removed is_fatal, is_level and log methods from Mojo::Log.
- Removed auto_render method from Mojolicious::Routes.
- Removed deprecated object-oriented Mojo::Loader API.
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/IOLoop/Client.pm
Expand Up @@ -162,8 +162,7 @@ sub _try_tls {
my ($self, $args) = @_;

my $handle = $self->{handle};
return $self->_cleanup->emit(connect => $handle)
if !$args->{tls} || $handle->isa('IO::Socket::SSL');
return $self->_cleanup->emit(connect => $handle) unless $args->{tls};
return $self->emit(error => 'IO::Socket::SSL 1.94+ required for TLS support')
unless TLS;

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Transaction.pm
Expand Up @@ -206,10 +206,10 @@ in a subclass.
=head2 connection
my $connection = $tx->connection;
$tx = $tx->connection($connection);
my $id = $tx->connection;
$tx = $tx->connection($id);
Connection identifier or socket.
Connection identifier.
=head2 error
Expand Down
7 changes: 3 additions & 4 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -183,10 +183,9 @@ sub _connection {
my ($self, $nb, $tx, $cb) = @_;

# Reuse connection
my $id = $tx->connection;
my ($proto, $host, $port) = $self->transactor->endpoint($tx);
$id ||= $self->_dequeue($nb, "$proto:$host:$port", 1);
if ($id && !ref $id) {
my $id = $tx->connection || $self->_dequeue($nb, "$proto:$host:$port", 1);
if ($id) {
warn "-- Reusing connection $id ($proto://$host:$port)\n" if DEBUG;
$self->{connections}{$id} = {cb => $cb, nb => $nb, tx => $tx};
$tx->kept_alive(1) unless $tx->connection;
Expand All @@ -198,7 +197,7 @@ sub _connection {
if (my $id = $self->_connect_proxy($nb, $tx, $cb)) { return $id }

# Connect
$id = $self->_connect($nb, 1, $tx, $id, \&_connected);
$id = $self->_connect($nb, 1, $tx, undef, \&_connected);
warn "-- Connect $id ($proto://$host:$port)\n" if DEBUG;
$self->{connections}{$id} = {cb => $cb, nb => $nb, tx => $tx};

Expand Down
4 changes: 0 additions & 4 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -377,10 +377,6 @@ requests, with support for L</"GENERATORS">.
# Generate and inspect custom GET request with DNT header and content
say $t->tx(GET => 'example.com' => {DNT => 1} => 'Bye!')->req->to_string;
# Use a custom socket for processing this transaction
my $tx = $t->tx(GET => 'http://example.com');
$tx->connection($sock);
# Stream response content to STDOUT
my $tx = $t->tx(GET => 'http://example.com');
$tx->res->content->unsubscribe('read')->on(read => sub { say $_[1] });
Expand Down
26 changes: 0 additions & 26 deletions t/mojo/user_agent_tls.t
Expand Up @@ -51,32 +51,6 @@ ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

# Valid certificates (using an already prepared socket)
my $sock;
$ua->ioloop->client(
{
address => '127.0.0.1',
port => $port,
tls => 1,
tls_ca => 't/mojo/certs/ca.crt',
tls_cert => 't/mojo/certs/client.crt',
tls_key => 't/mojo/certs/client.key'
} => sub {
my ($loop, $err, $stream) = @_;
$sock = $stream->steal_handle;
$stream->close;
$loop->stop;
}
);
$ua->ioloop->start;
$tx = $ua->build_tx(GET => 'https://lalala/')->connection($sock);
$ua->start($tx);
ok $tx->success, 'successful';
is $tx->req->method, 'GET', 'right method';
is $tx->req->url, 'https://lalala/', 'right url';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

# Valid certificates (env)
$ua = Mojo::UserAgent->new(ioloop => $ua->ioloop);
{
Expand Down
46 changes: 3 additions & 43 deletions t/mojo/websocket.t
Expand Up @@ -45,16 +45,6 @@ get '/something/else' => sub {
$c->render(text => "${timeout}failed!");
};

websocket '/socket' => sub {
my $c = shift;
$c->send(
$c->req->headers->host => sub {
my $c = shift;
$c->send(Mojo::IOLoop->stream($c->tx->connection)->timeout)->finish;
}
)->rendered(101);
};

websocket '/early_start' => sub {
my $c = shift;
$c->send('test1');
Expand Down Expand Up @@ -133,7 +123,7 @@ is $res->code, 200, 'right status';
like $res->body, qr!ws://127\.0\.0\.1:\d+/!, 'right content';

# Plain HTTP request
$res = $ua->get('/socket')->res;
$res = $ua->get('/early_start')->res;
is $res->code, 404, 'right status';
like $res->body, qr/Page not found/, 'right content';

Expand Down Expand Up @@ -169,37 +159,6 @@ ok !$ws, 'not a WebSocket';
is $code, 200, 'right status';
ok $body =~ /^(\d+)failed!$/ && $1 == 15, 'right content';

# Using an already prepared socket
my $sock;
Mojo::IOLoop->client(
{address => '127.0.0.1', port => $ua->server->nb_url->port} => sub {
my ($loop, $err, $stream) = @_;
$sock = $stream->steal_handle;
$stream->close;
Mojo::IOLoop->stop;
}
);
Mojo::IOLoop->start;
my $tx = $ua->build_websocket_tx('ws://lalala/socket')->connection($sock);
my $finished;
$tx->on(finish => sub { $finished++ });
$result = '';
my $early;
$ua->start(
$tx => sub {
my ($ua, $tx) = @_;
$early = $finished;
$tx->on(finish => sub { Mojo::IOLoop->stop });
$tx->on(message => sub { $result .= pop });
}
);
Mojo::IOLoop->start;
is $finished, 1, 'finish event has been emitted once';
is $early, 1, 'finish event has been emitted at the right time';
ok $result =~ /^lalala(\d+)$/ && $1 == 15, 'right result';
is(Mojo::IOLoop->stream($tx->connection)->handle, $sock,
'right connection id');

# Server directly sends a message
$result = undef;
my ($status, $msg);
Expand Down Expand Up @@ -355,7 +314,8 @@ Mojo::IOLoop->start;
is $result, 'foo bar', 'right result';

# Dies
($finished, $ws, $code, $msg) = ();
($ws, $code, $msg) = ();
my $finished;
$ua->websocket(
'/dead' => sub {
my ($ua, $tx) = @_;
Expand Down

0 comments on commit 1712764

Please sign in to comment.