### ----------------------------------------------------
### -- Humming-Bird
### -- Licenses: MIT
### -- Authors: Rawley Fowler
### -- File: t/03-response_decoding.rakutest
### ----------------------------------------------------
use v6;
use strict;
use lib 'lib';

use Test;
use Humming-Bird::Core;
use Humming-Bird::Glue;
use HTTP::Status;

plan 6;

my $initiator = Request.new(path => '/', method => GET, version => 'HTTP/1.1');
my $simple_response = Response.new(:$initiator, status => HTTP::Status(200));

$simple_response.write('Foo');
$simple_response.header('Content-Type', 'text/plain');

ok my $simple_response_str = $simple_response.encode, 'Does decode not die?';

my $simple_response_headers = Response.new(:$initiator, status => HTTP::Status(200));

$simple_response_headers.header('Content-Length', 10.Str).header('Encoding', 'utf-8');

ok $simple_response_headers.header('encoding');
ok $simple_response_headers.header('content-LENGTH');

ok $simple_response_headers.encode, 'Does encode with headers not die?';
$simple_response_headers.write('abc');
is $simple_response_headers.encode.subbuf(*-3), Buf.new(<abc>.ords);

ok $simple_response_str.decode.contains('content-type: text/plain; charset=utf-8');

done-testing;


