### ----------------------------------------------------
### -- Net::HTTP
### -- Licenses: Artistic-2.0
### -- Authors: ugexe
### -- File: t/03-request.rakutest
### ----------------------------------------------------
use Test:ver<6.c+>;
plan 1;

use Net::HTTP::Request;
use Net::HTTP::URL;

subtest 'Basic: request header tests' => {
    my $want-str = q{GET /search?x=1 HTTP/1.1}
        ~ "\r\n" ~ q{Host: google.com}
        ~ "\r\n" ~ q{User-Agent: raku-net-http}
        ~ "\r\n\r\n";

    my $url     = Net::HTTP::URL.new("http://google.com/search?x=1");
    my $method  = 'GET';
    my %header  = :Host<google.com>, :User-Agent("raku-net-http");

    my $request = Net::HTTP::Request.new(:$url, :$method, :%header);
    is $request.Str.chars, $want-str.chars;

    subtest {
        temp %header;
        %header<Host>:delete if %header<Host>:exists;
        my $request = Net::HTTP::Request.new(:$url, :$method, :%header);

        my @want = $want-str.lines;
        my @got  = $request.Str.lines;
        for @want {
            ok $_ ~~ any(@got);
        }
    }, 'Auto setting the host header';
}

done-testing;


