Skip to content

Commit

Permalink
check the listen location
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 7, 2015
1 parent 9f11ccd commit 162016b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

6.11 2015-04-28
6.11 2015-05-07
- Updated jQuery to version 2.1.4.

6.10 2015-04-26
Expand Down
9 changes: 7 additions & 2 deletions lib/Mojo/Server/Daemon.pm
@@ -1,6 +1,7 @@
package Mojo::Server::Daemon;
use Mojo::Base 'Mojo::Server';

use Carp 'croak';
use Mojo::IOLoop;
use Mojo::URL;
use Mojo::Util 'term_escape';
Expand Down Expand Up @@ -146,7 +147,11 @@ sub _finish {
sub _listen {
my ($self, $listen) = @_;

my $url = Mojo::URL->new($listen);
my $url = Mojo::URL->new($listen);
my $proto = $url->protocol;
croak qq{Invalid listen location "$listen"}
unless $proto eq 'http' || $proto eq 'https';

my $query = $url->query;
my $options = {
address => $url->host,
Expand All @@ -158,7 +163,7 @@ sub _listen {
my $verify = $query->param('verify');
$options->{tls_verify} = hex $verify if defined $verify;
delete $options->{address} if $options->{address} eq '*';
my $tls = $options->{tls} = $url->protocol eq 'https';
my $tls = $options->{tls} = $proto eq 'https';

weaken $self;
push @{$self->acceptors}, $self->ioloop->server(
Expand Down
4 changes: 4 additions & 0 deletions t/mojo/daemon.t
Expand Up @@ -96,6 +96,10 @@ eval { Mojo::Server::Daemon->new->build_app('Mojo::DoesNotExist') };
like $@, qr/^Can't find application class "Mojo::DoesNotExist" in \@INC/,
'right error';

# Invalid listen location
eval { Mojo::Server::Daemon->new(listen => ['fail'])->start };
like $@, qr/Invalid listen location/, 'right error';

# Transaction
isa_ok $app->build_tx, 'Mojo::Transaction::HTTP', 'right transaction';

Expand Down

0 comments on commit 162016b

Please sign in to comment.