From a692f2abb82c6c079d78695f2b750776fb9a7f72 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:08:15 +0100 Subject: [PATCH 01/22] no our scoped class inside a role anymore --- lib/HTTP/Server/Simple.pm6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HTTP/Server/Simple.pm6 b/lib/HTTP/Server/Simple.pm6 index 9889bdc..2727022 100644 --- a/lib/HTTP/Server/Simple.pm6 +++ b/lib/HTTP/Server/Simple.pm6 @@ -8,7 +8,7 @@ role HTTP::Server::Simple { has Str $!request; has Str @!headers; - class Output-Interceptor { + my class Output-Interceptor { has $.socket is rw; multi method print(*@a) { # $*ERR.say: "Intercepting print " ~ @a; From ed998bd85c987973f2666b9c3ce7b24a3e4f0db5 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:09:56 +0100 Subject: [PATCH 02/22] it's a LoL, so we need to destructure --- lib/HTTP/Server/Simple.pm6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HTTP/Server/Simple.pm6 b/lib/HTTP/Server/Simple.pm6 index 2727022..0c5d170 100644 --- a/lib/HTTP/Server/Simple.pm6 +++ b/lib/HTTP/Server/Simple.pm6 @@ -91,7 +91,7 @@ role HTTP::Server::Simple { :$query_string, :$localport, :$peername, :$peeraddr, :$localname ) { } method headers (@headers) { - for @headers -> $key, $value { + for @headers -> [$key, $value] { self.header( $key, $value ); } } From 24d0ef065a8930c382bb66431679f2b0f77a18ae Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:13:45 +0100 Subject: [PATCH 03/22] it's IO::Socket::INET::print now --- lib/HTTP/Server/Simple.pm6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/HTTP/Server/Simple.pm6 b/lib/HTTP/Server/Simple.pm6 index 0c5d170..2ce7622 100644 --- a/lib/HTTP/Server/Simple.pm6 +++ b/lib/HTTP/Server/Simple.pm6 @@ -12,11 +12,11 @@ role HTTP::Server::Simple { has $.socket is rw; multi method print(*@a) { # $*ERR.say: "Intercepting print " ~ @a; - $.socket.send(@a); + $.socket.print(@a); } multi method say(*@a) { # $*ERR.say: "Intercepting say " ~ @a; - $.socket.send(@a ~ "\x0D\x0A"); + $.socket.print(@a ~ "\x0D\x0A"); } } From 6537ca9b845127de62bd4d33473694057e8b52d7 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:15:00 +0100 Subject: [PATCH 04/22] remove dead code --- lib/HTTP/Server/Simple.pm6 | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/HTTP/Server/Simple.pm6 b/lib/HTTP/Server/Simple.pm6 index 2ce7622..c2253a5 100644 --- a/lib/HTTP/Server/Simple.pm6 +++ b/lib/HTTP/Server/Simple.pm6 @@ -21,7 +21,6 @@ role HTTP::Server::Simple { } method new ( $port=8080 ) { - my %methods = self.^methods Z 1..*; # convert list to hash pairs self.bless( self.CREATE(), # self might also be a subclass port => $port, host => self.lookup_localhost, From f880bde2b9f136b448e8681866cc9a707545c69b Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:18:08 +0100 Subject: [PATCH 05/22] exists exists somewhere else now --- lib/HTTP/Server/Simple/PSGI.pm6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HTTP/Server/Simple/PSGI.pm6 b/lib/HTTP/Server/Simple/PSGI.pm6 index d8b3767..2f1234b 100644 --- a/lib/HTTP/Server/Simple/PSGI.pm6 +++ b/lib/HTTP/Server/Simple/PSGI.pm6 @@ -40,7 +40,7 @@ class HTTP::Server::Simple::PSGI does HTTP::Server::Simple { $key = 'HTTP_' ~ $key unless $key eq any(); # RAKUDO: :exists doesn't exist yet - if %!env.exists($key) { + if %!env{$key}:exists { # This is how P5 Plack::HTTPParser::PP handles this %!env{$key} ~= ", $value"; } From 53f5c5a3f52c67e5adffe5ab21ec08f161437e4c Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:19:42 +0100 Subject: [PATCH 06/22] destructure LoL --- lib/HTTP/Server/Simple/PSGI.pm6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HTTP/Server/Simple/PSGI.pm6 b/lib/HTTP/Server/Simple/PSGI.pm6 index 2f1234b..dfb90c3 100644 --- a/lib/HTTP/Server/Simple/PSGI.pm6 +++ b/lib/HTTP/Server/Simple/PSGI.pm6 @@ -34,7 +34,7 @@ class HTTP::Server::Simple::PSGI does HTTP::Server::Simple { }; } method headers (@headers) { - for @headers -> $key is copy, $value { + for @headers -> [$key is copy, $value] { $key ~~ s:g /\-/_/; $key .= uc; From c38bd7542fd3b4abaea2d192f1c22e3cef648ba7 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:21:28 +0100 Subject: [PATCH 07/22] it's IO::Socket::INET::print now --- lib/HTTP/Server/Simple/PSGI.pm6 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/HTTP/Server/Simple/PSGI.pm6 b/lib/HTTP/Server/Simple/PSGI.pm6 index dfb90c3..f69e082 100644 --- a/lib/HTTP/Server/Simple/PSGI.pm6 +++ b/lib/HTTP/Server/Simple/PSGI.pm6 @@ -63,13 +63,13 @@ class HTTP::Server::Simple::PSGI does HTTP::Server::Simple { # $*ERR.say: "Status: $status"; # $*ERR.say: "Headers: {@headers}"; # $*ERR.say: "Body: {@body}"; - $.connection.send( "HTTP/1.1 $status OK\x0D\x0A" ); - $.connection.send( + $.connection.print( "HTTP/1.1 $status OK\x0D\x0A" ); + $.connection.print( @headers.map({ $_[0].key ~ ': ' ~ $_[0].value }).join("\n") ); - $.connection.send( "\x0D\x0A" ); - $.connection.send( "\x0D\x0A" ); - $.connection.send( @body ); + $.connection.print( "\x0D\x0A" ); + $.connection.print( "\x0D\x0A" ); + $.connection.print( @body ); # $*ERR.say: "end PSGI.handler"; } } From b1f5f04ec168e8452c6ac857bef87904e1c61723 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:22:32 +0100 Subject: [PATCH 08/22] we don't want to assign a hash of pairs to a hash --- lib/HTTP/Server/Simple/PSGI.pm6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/HTTP/Server/Simple/PSGI.pm6 b/lib/HTTP/Server/Simple/PSGI.pm6 index f69e082..0ae95f1 100644 --- a/lib/HTTP/Server/Simple/PSGI.pm6 +++ b/lib/HTTP/Server/Simple/PSGI.pm6 @@ -13,7 +13,7 @@ class HTTP::Server::Simple::PSGI does HTTP::Server::Simple { method setup ( :$localname, :$localport, :$method, :$request_uri, :$path, :$query_string, :$peername, :$peeraddr, *%rest ) { - %!env = { + %!env = 'SERVER_NAME' => $localname, 'SERVER_PORT' => $localport, 'REQUEST_METHOD' => $method, @@ -31,7 +31,7 @@ class HTTP::Server::Simple::PSGI does HTTP::Server::Simple { 'psgi.runonce' => Bool::False, 'psgi.nonblocking' => Bool::False, 'psgi.streaming' => Bool::False, - }; + ; } method headers (@headers) { for @headers -> [$key is copy, $value] { From ecc944aa39f9e83d69699fd40fc75995ffdbba51 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:26:58 +0100 Subject: [PATCH 09/22] type objects don't turn themselves into strings --- lib/HTTP/Server/Simple/PSGI.pm6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/HTTP/Server/Simple/PSGI.pm6 b/lib/HTTP/Server/Simple/PSGI.pm6 index 0ae95f1..08bbba8 100644 --- a/lib/HTTP/Server/Simple/PSGI.pm6 +++ b/lib/HTTP/Server/Simple/PSGI.pm6 @@ -56,13 +56,13 @@ class HTTP::Server::Simple::PSGI does HTTP::Server::Simple { # Instead it calls handle_response later on. my $response_ref = defined($!psgi_app) ?? $!psgi_app(%!env) # app must return [status,[headers],[body]] - !! [500,[Content-Type => 'text/plain'],[self.WHAT,"app missing"]]; + !! [500,[Content-Type => 'text/plain'],[self.WHAT.perl,"app missing"]]; my $status = $response_ref[0]; my @headers = $response_ref[1]; my @body = $response_ref[2]; # $*ERR.say: "Status: $status"; # $*ERR.say: "Headers: {@headers}"; - # $*ERR.say: "Body: {@body}"; + # $*ERR.say: "Body: {@body}"; $.connection.print( "HTTP/1.1 $status OK\x0D\x0A" ); $.connection.print( @headers.map({ $_[0].key ~ ': ' ~ $_[0].value }).join("\n") From 2a7e90ec7aa177c6a3f07f9117666f679aec8948 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 22:52:54 +0100 Subject: [PATCH 10/22] hostile takeover --- META.info | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/META.info b/META.info index d8a6c80..2015fc0 100644 --- a/META.info +++ b/META.info @@ -2,10 +2,11 @@ "name" : "HTTP::Server::Simple", "version" : "*", "description" : "Simple webserver module, with PSGI support", + "authors" : [ "Martin Berends", "Wenzel P. P. Peppmeyer" ], "provides" : { "HTTP::Server::Simple" : "lib/HTTP/Server/Simple.pm6", "HTTP::Server::Simple::PSGI" : "lib/HTTP/Server/Simple/PSGI.pm6" }, "depends" : [], - "source-url" : "git://github.com/mberends/http-server-simple.git" + "source-url" : "git://github.com/gfldex/http-server-simple.git" } From bf22ec0303160c1b4e91d816f9eb95660563bd4b Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Mon, 4 Jan 2016 23:10:28 +0100 Subject: [PATCH 11/22] add simple test --- t/basic.t | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 t/basic.t diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..7619ab6 --- /dev/null +++ b/t/basic.t @@ -0,0 +1,15 @@ +use v6; +use lib 'lib'; +use Test; +use HTTP::Server::Simple; +use HTTP::Server::Simple::PSGI; + + +plan 2; + +my $server = HTTP::Server::Simple.new; +ok($server ~~ HTTP::Server::Simple, 'HTTP::Server::Simple can be constructed'); + +$server = HTTP::Server::Simple::PSGI.new; +ok($server ~~ HTTP::Server::Simple::PSGI, 'HTTP::Server::Simple::PSGI can be constructed'); + From 3ca7774009029ca24aa96ef64c0baa8de25109af Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Tue, 5 Jan 2016 01:51:32 +0100 Subject: [PATCH 12/22] add travis support --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7de4080 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: perl6 +sudo: false +perl6: + - latest From 822d48863be78688f5951563c9defee0010abe52 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Tue, 5 Jan 2016 03:00:40 +0100 Subject: [PATCH 13/22] for the first travis build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7de4080..af55269 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,4 @@ language: perl6 sudo: false perl6: - latest + From 747348422cd3c9a0b51b93f2b5ba81b60331a209 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Tue, 5 Jan 2016 03:14:01 +0100 Subject: [PATCH 14/22] add required fields to META.info --- META.info | 2 ++ 1 file changed, 2 insertions(+) diff --git a/META.info b/META.info index 2015fc0..200f14a 100644 --- a/META.info +++ b/META.info @@ -1,4 +1,5 @@ { + "perl" : "6.*, "name" : "HTTP::Server::Simple", "version" : "*", "description" : "Simple webserver module, with PSGI support", @@ -8,5 +9,6 @@ "HTTP::Server::Simple::PSGI" : "lib/HTTP/Server/Simple/PSGI.pm6" }, "depends" : [], + "resources" : [], "source-url" : "git://github.com/gfldex/http-server-simple.git" } From c6f480d21ffe1fc20bc6fced0e25967a7f020733 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Tue, 5 Jan 2016 08:01:47 +0100 Subject: [PATCH 15/22] fixed META.info --- META.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/META.info b/META.info index 200f14a..32876e4 100644 --- a/META.info +++ b/META.info @@ -1,5 +1,5 @@ { - "perl" : "6.*, + "perl" : "6.*", "name" : "HTTP::Server::Simple", "version" : "*", "description" : "Simple webserver module, with PSGI support", From 02ad4721ced8a3febaa7962a79a11de75e17e54f Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Fri, 8 Jan 2016 16:33:35 +0100 Subject: [PATCH 16/22] convert README to markdown --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7635a86 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# HTTP::Server::Simple + +[![Build Status](https://travis-ci.org/gfldex/http-server-simple.svg?branch=master)](https://travis-ci.org/gfldex/http-server-simple) + +This simple embedded web server is similar to HTTP::Daemon, but provides +more hooks for subclassing and extending. The subclasses CGI and PSGI give +ways to host existing web applications or frameworks that use those APIs. + +The Perl Server Gateway Interface is a more powerful and efficient web +server API than CGI. Several well known Perl 5 products are based on it, +for example Plack and Dancer. This Perl 6 based project offers the same +web server foundation on Rakudo, to assist the porting of such web +frameworks to Perl 6. + +The object hierarchy follows its Perl 5 based prototype closely, except +where the CGI concerns were not separated from the web server. In this +Perl 6 implementation the PSGI concerns are fully separated from the CGI +ones. + +# EXAMPLES + +Included are examples of minimal web servers and some that demonstrate use +of extension hooks and subclassing. + +# TESTING + +The code is badly under tested, contributions would be welcome. + +# SEE ALSO + +The Perl 6 Web.pm project: http://github.com/masak/web +The Perl Dancer project: perldancer.org +PSGI spec: http://github.com/miyagawa/psgi-specs/blob/master/PSGI.pod +Rack spec: http://rack.rubyforge.org/doc/SPEC.html From b1902651a9f824faec5544ad7dab1624f9fff190 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Sat, 9 Jul 2016 03:13:26 +0200 Subject: [PATCH 17/22] fix constructor --- lib/HTTP/Server/Simple.pm6 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/HTTP/Server/Simple.pm6 b/lib/HTTP/Server/Simple.pm6 index c2253a5..0c90f78 100644 --- a/lib/HTTP/Server/Simple.pm6 +++ b/lib/HTTP/Server/Simple.pm6 @@ -1,9 +1,9 @@ # HTTP/Server/Simple.pm6 -role HTTP::Server::Simple { +role HTTP::Server::Simple[IO::Socket ::SocketType = IO::Socket::INET] { has $.port; has $.host is rw; - has IO::Socket::INET $!listener; + has SocketType $!listener; has $.connection; # returned by accept() has Str $!request; has Str @!headers; @@ -20,8 +20,8 @@ role HTTP::Server::Simple { } } - method new ( $port=8080 ) { - self.bless( self.CREATE(), # self might also be a subclass + method new ( :$port = 8080 ) { + self.bless( port => $port, host => self.lookup_localhost, ); From c695b7249fd9b8ac2993cc4b268ec42a867ce14d Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Sat, 9 Jul 2016 03:13:50 +0200 Subject: [PATCH 18/22] add travis and bump version --- .travis.yml | 3 +++ META.info | 8 ++++---- README | 32 -------------------------------- 3 files changed, 7 insertions(+), 36 deletions(-) delete mode 100644 README diff --git a/.travis.yml b/.travis.yml index af55269..7b9b85f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,7 @@ language: perl6 sudo: false perl6: - latest +install: + - rakudobrew build-panda + - panda install . diff --git a/META.info b/META.info index 32876e4..b1a517c 100644 --- a/META.info +++ b/META.info @@ -1,14 +1,14 @@ { - "perl" : "6.*", + "perl" : "6.*", "name" : "HTTP::Server::Simple", - "version" : "*", + "version" : "0.1.2", "description" : "Simple webserver module, with PSGI support", - "authors" : [ "Martin Berends", "Wenzel P. P. Peppmeyer" ], + "authors" : [ "Martin Berends", "Wenzel P. P. Peppmeyer" ], "provides" : { "HTTP::Server::Simple" : "lib/HTTP/Server/Simple.pm6", "HTTP::Server::Simple::PSGI" : "lib/HTTP/Server/Simple/PSGI.pm6" }, "depends" : [], - "resources" : [], + "resources" : [], "source-url" : "git://github.com/gfldex/http-server-simple.git" } diff --git a/README b/README deleted file mode 100644 index fce7f99..0000000 --- a/README +++ /dev/null @@ -1,32 +0,0 @@ -README for the Rakudo Perl 6 version of HTTP::Server::Simple - -This simple embedded web server is similar to HTTP::Daemon, but provides -more hooks for subclassing and extending. The subclasses CGI and PSGI give -ways to host existing web applications or frameworks that use those APIs. - -The Perl Server Gateway Interface is a more powerful and efficient web -server API than CGI. Several well known Perl 5 products are based on it, -for example Plack and Dancer. This Perl 6 based project offers the same -web server foundation on Rakudo, to assist the porting of such web -frameworks to Perl 6. - -The object hierarchy follows its Perl 5 based prototype closely, except -where the CGI concerns were not separated from the web server. In this -Perl 6 implementation the PSGI concerns are fully separated from the CGI -ones. - -EXAMPLES - -Included are examples of minimal web servers and some that demonstrate use -of extension hooks and subclassing. - -TESTING - -The code is badly under tested, contributions would be welcome. - -SEE ALSO - -The Perl 6 Web.pm project: http://github.com/masak/web -The Perl Dancer project: perldancer.org -PSGI spec: http://github.com/miyagawa/psgi-specs/blob/master/PSGI.pod -Rack spec: http://rack.rubyforge.org/doc/SPEC.html From 38d45970beb9f2f5c541039f2d7e057446336edd Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Tue, 25 Apr 2017 10:05:29 -0400 Subject: [PATCH 19/22] Use modern META filename The `META.info` is a legacy, pre-Christmas name. While it's still currently supported, `META6.json` is the new name. And since a lot of people simply copy some module's structure, the old name still proliferates, so we're trying to get rid of it for good by sending PRs to any modules that use the old name, to switch to the modern name. --- META.info => META6.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename META.info => META6.json (100%) diff --git a/META.info b/META6.json similarity index 100% rename from META.info rename to META6.json From e29ecf21169ddebc12abca1dfc09d1ed4d4a1704 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Sun, 30 Jul 2017 15:50:37 +0200 Subject: [PATCH 20/22] add meta.t --- t/meta.t | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 t/meta.t diff --git a/t/meta.t b/t/meta.t new file mode 100644 index 0000000..0d7d371 --- /dev/null +++ b/t/meta.t @@ -0,0 +1,9 @@ +use v6; + +use lib 'lib'; +use Test; +use Test::META; + +meta-ok; + +done-testing; From 218a328603499a41e231f122e2ebf4146c8067b6 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Sun, 30 Jul 2017 16:00:56 +0200 Subject: [PATCH 21/22] panda-- zef++ --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b9b85f..1b266e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,6 @@ sudo: false perl6: - latest install: - - rakudobrew build-panda - - panda install . + - rakudobrew build-zef + - zef --debug install . From 13390c5eb8315f60a4e28517349f23109b6fa740 Mon Sep 17 00:00:00 2001 From: "Wenzel P. P. Peppmeyer" Date: Sun, 30 Jul 2017 16:09:47 +0200 Subject: [PATCH 22/22] add misssing dep --- META6.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/META6.json b/META6.json index b1a517c..3f89a08 100644 --- a/META6.json +++ b/META6.json @@ -8,7 +8,7 @@ "HTTP::Server::Simple" : "lib/HTTP/Server/Simple.pm6", "HTTP::Server::Simple::PSGI" : "lib/HTTP/Server/Simple/PSGI.pm6" }, - "depends" : [], + "depends" : [ "Test::META" ], "resources" : [], "source-url" : "git://github.com/gfldex/http-server-simple.git" }