mojolicious / mojo

:sparkles: Mojolicious - Perl real-time web framework
https://mojolicious.org
Artistic License 2.0
2.66k stars 577 forks source link

URL parsed from a serialised request is never absolute #2141

Closed choroba closed 9 months ago

choroba commented 9 months ago

Steps to reproduce the behavior

#! /usr/bin/perl
use warnings;
use strict;
use feature qw{ say };

use Mojo::Message::Request;
use Mojo::URL;

my $url1 = 'Mojo::URL'->new('http://example.com');
say $url1->to_string, ' ', $url1->is_abs ? 'abs' : '!abs';  # Is absolute.

my $txt = join "\r\n", 'GET / HTTP/1.1', 'Host: example.com', "", "";
my $url2 = 'Mojo::Message::Request'->new->parse($txt)->url;
say $url2->to_string, ' ', $url2->is_abs ? 'abs' : '!abs';  # Isn't absolute!

Expected behavior

$url2 should be absolute.

Actual behavior

$url2 is not absolute.

This leads to unexpected behaviour: when a serialised (to_string) request is parsed into a request and this request is started, it fails. See this StackOverflow question.