### ----------------------------------------------------
### -- Net::HTTP
### -- Licenses: Artistic-2.0
### -- Authors: ugexe
### -- File: xt/issues.rakutest
### ----------------------------------------------------
use Test:ver<6.c+>;
plan 2;

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

diag('https://github.com/ugexe/Raku-Net--HTTP/issues/8 - thread interpolation while stringifying requests via "{...}"');
{
   my @failures;
   await (^5).map: -> $tid {
      start {
         for ^10 -> $index {
            my $url    = Net::HTTP::URL.new("http://www.google.com/$tid/$index/");
            my %header = :Connection<keep-alive>, :User-Agent<raku-net-http>, :Tid($tid), :Index($index);
            my $req    = Net::HTTP::Request.new: :$url, :method<GET>, :%header;

            @failures.push("index:$index tid:$tid -- {$req.Str.lines.join(' ')}")
               unless $req.Str ~~ /[:i "Tid:"]\s$tid/, "tid:$tid -- {$req.Str.lines.join(' ')}"
                  && $req.Str ~~ /[:i Index]\:\s$index/, "index:$index -- {$req.Str.lines.join(' ')}";
         }
      }
   }
   is +@failures, 0;
}

subtest 'https://github.com/ugexe/Raku-Net--HTTP/issues/11 - Net::HTTP::Request::raw explodes on large (> 64kb) requests' => {
   my $request = Net::HTTP::Request.new(
      :url(Net::HTTP::URL.new("http://www.google.com/")),
      :method<GET>,
      :body("x" x (2 ** 16)),
      :header({}),
   );

   lives-ok { $request.raw().sink }
}

done-testing;


