Skip to content

Document somewhere that Mojolicious::Lite initializes Mojo::UserAgent::Server. #2283

@EugenKon

Description

@EugenKon

It is very surprising how UA knows which server to send requests.

use Mojolicious::Lite;
use Mojo::UserAgent;


get '/test' => sub{ shift->render( text => 'Ok' ) };

print "Response: " .Mojo::UserAgent->new->get( '/test' )->result->body ."\n";

1;

Document somewhere that Mojolicious::Lite changes Mojo::UserAgent::Server.

I found nothing here https://docs.mojolicious.org/Mojolicious/Lite or here https://docs.mojolicious.org/Mojo/UserAgent
and even here https://docs.mojolicious.org/Mojo/UserAgent/Server

It seems this could be bit dangerous, because if a 3rd party module loads Mojolicious::Lite, then UA in current module module is not just clean UA:

use Mojo::UserAgent;
use Some::Module;

my $ua =  Mojo::UserAgent->new;

Though, overall I like the idea that if the URL is not absolute, then the request goes to the current application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions