<commit_before>#!/usr/bin/env perl6-j

use HTTP::Server::Async;
use Test;

plan 10;

my $s = HTTP::Server::Async.new;
isa_ok $s, HTTP::Server::Async;
is $s.responsestack.elems, 0, 'Response stack contains no elements yet';

$s.register(sub ($req,$res,$n) {
  start {
    sleep 2;
    $n.();
  };
});

$s.register(sub ($request, $response, $n) {
  $response.headers<Content-Type> = 'text/plain';
  $response.status = 200;
  $response.write("");
  $response.close("Hello world!");
});
ok $s.responsestack.elems, 'Response stack contains elements';
isa_ok $s.responsestack[0], Sub;

$s.listen;

my $host = '127.0.0.1';
my $port = 8080;
 
my $client = IO::Socket::INET.new(:$host, :$port);
isa_ok $client, IO::Socket::INET;
is $client.host, $host, 'IO::Socket::INET correct host';
is $client.port, $port, 'IO::Socket::INET correct port';

$client.send("GET / HTTP/1.0\r\n\r\n");
my @data;
while (my $str = $client.recv) {
  @data.push($str);
}
$client.close;

is @data[0], "HTTP/1.1 200 OK\r\n", "Code: 200";
is @data[1], "Content-Type: text/plain\r\nContent-Length: 12\r\n\r\n", "Content-type correct";
is @data[2], "Hello world!", "Content: Hello World!";
<commit_msg>expect the "Connection: close" in responses in tests as well<commit_after>#!/usr/bin/env perl6-j

use HTTP::Server::Async;
use Test;

plan 10;

my $s = HTTP::Server::Async.new;
isa_ok $s, HTTP::Server::Async;
is $s.responsestack.elems, 0, 'Response stack contains no elements yet';

$s.register(sub ($req,$res,$n) {
  start {
    sleep 2;
    $n.();
  };
});

$s.register(sub ($request, $response, $n) {
  $response.headers<Content-Type> = 'text/plain';
  $response.status = 200;
  $response.write("");
  $response.close("Hello world!");
});
ok $s.responsestack.elems, 'Response stack contains elements';
isa_ok $s.responsestack[0], Sub;

$s.listen;

my $host = '127.0.0.1';
my $port = 8080;
 
my $client = IO::Socket::INET.new(:$host, :$port);
isa_ok $client, IO::Socket::INET;
is $client.host, $host, 'IO::Socket::INET correct host';
is $client.port, $port, 'IO::Socket::INET correct port';

$client.send("GET / HTTP/1.0\r\n\r\n");
my @data;
while (my $str = $client.recv) {
  @data.push($str);
}
$client.close;

is @data[0], "HTTP/1.1 200 OK\r\n", "Code: 200";
is @data[1], "Content-Type: text/plain\r\nConnection: close\r\nContent-Length: 12\r\n\r\n", "Content-type correct";
is @data[2], "Hello world!", "Content: Hello World!";

{'fraction_non_alphanumeric': 0.22, 'fraction_numerical': 0.028333333333333332, 'mean_word_length': 4.649411764705882, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3253662', 'n_tokens_mistral': 1000, 'n_tokens_neox': 957, 'n_words': 222}