Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Created January 26, 2016 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanstowe/e0d76e413751a9302729 to your computer and use it in GitHub Desktop.
Save jonathanstowe/e0d76e413751a9302729 to your computer and use it in GitHub Desktop.
The really really dumb server
use v6;
my sub _index_buf(Blob $input, Blob $sub) {
my $end-pos = 0;
while $end-pos < $input.bytes {
if $sub eq $input.subbuf($end-pos, $sub.bytes) {
return $end-pos;
}
$end-pos++;
}
return -1;
}
react {
whenever IO::Socket::Async.listen('localhost',3333) -> $conn {
whenever $conn.Supply(:bin) -> $buf {
my $header-end = _index_buf($buf, Buf.new(13,10));
my $out-buf = "HTTP/1.0 200 OK\r\n".encode ~ $buf.subbuf($header-end);
await $conn.write: $out-buf ;
$conn.close;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment