Mojo::UserAgent::SecureServer - Secure application server for Mojo::UserAgent
# Construct from Mojo::UserAgent my $ua = Mojo::UserAgent->new; $ua->ca('ca.pem')->cert('cert.pem')->key('key.pem'); $ua->server(Mojo::UserAgent::SecureServer->from_ua($ua)); # Construct manually my $ua = Mojo::UserAgent->new; my $server = Mojo::UserAgent::SecureServer->new; $server->listen(Mojo::URL->new('https://127.0.0.1?cert=/x/server.crt&key=/y/server.key&ca=/z/ca.crt')); $ua->server($server); # Test::Mojo my $app = Mojolicious->new; $app->routes->get('/' => sub { my $c = shift; my $handle = Mojo::IOLoop->stream($c->tx->connection)->handle; $c->render(json => {cn => $handle->peer_certificate('cn')}); }); my $t = Test::Mojo->new($app); $t->ua->insecure(0); $t->ua->ca('t/pki/certs/ca-chain.cert.pem') ->cert('t/pki/mojo.example.com.cert.pem') ->key('t/pki/mojo.example.com.key.pem'); $t->ua->server(Mojo::UserAgent::SecureServer->from_ua($t->ua)); $t->get_ok('/')->status_is(200)->json_is('/cn', 'mojo.example.com');
Mojo::UserAgent::SecureServer allows you to test your Mojolicious web application with custom SSL/TLS key/cert/ca.
Mojo::UserAgent::SecureServer inherits all attributes from Mojo::UserAgent::Server and implements the following new ones.
$url = $server->listen; $server = $server->listen(Mojo::URL->new('https://127.0.0.1'));
The base listen URL for Mojo::Server::Daemon created by "nb_url" and "url". The "port" will be discarded, while other "listen" in Mojo::Server::Daemon parameters are kept.
Mojo::UserAgent::SecureServer inherits all methods from Mojo::UserAgent::Server and implements the following new ones.
$server = Mojo::UserAgent::SecureServer->from_ua($ua); $server = $server->from_ua($ua);
Used to construct a new object and/or copy attributes from a Mojo::UserAgent object. Here is the long version:
$server->app($ua->server->app); $server->ioloop($ua->server->ioloop); $server->listen->query->param(ca => $ua->ca); $server->listen->query->param(cert => $ua->cert); $server->listen->query->param(key => $ua->key); $server->listen->query->param(verify => Net::SSLeay::VERIFY_PEER()) unless $ua->insecure
$url = $server->nb_url;
Get absolute Mojo::URL object for server processing non-blocking requests with "app" in Mojo::UserAgent::Server.
$url = $server->url;
Jan Henning Thorsen
Copyright (C) Jan Henning Thorsen.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Mojo::UserAgent, Mojo::UserAgent::Server and Test::Mojo.
To install Mojo::UserAgent::SecureServer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::UserAgent::SecureServer
CPAN shell
perl -MCPAN -e shell install Mojo::UserAgent::SecureServer
For more information on module installation, please visit the detailed CPAN module installation guide.