Skip to content

Commit

Permalink
fix issue #33
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-o committed Feb 10, 2019
1 parent 657ff34 commit 345383e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
17 changes: 8 additions & 9 deletions examples/connection_hijack.pl6
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
#!/usr/bin/env perl6

use lib '../lib';
use lib 'lib';
use lib 'examples/lib';
use HTTP::Server::Async;
use HTTP::Server::Async::Plugins::Middleware::Hijack;

my $s = HTTP::Server::Async.new;
$s.middleware('HTTP::Server::Async::Plugins::Middleware::Hijack');
$s.middleware(&hijack);

#note that these handlers are never called, check
# <repo>/examples/lib/HTTP/Server/Async/Plugins/Middleware/Hijack.pm6
# for more info
$s.register(sub ($request, $response, $last) {
$s.handler(sub ($request, $response) {
$response.status = 404;
'Registered sub called.'.say;
#this is never called!
$response.write('Registered Sub');
$response.close;
$last(True); #Don't continue
False; #Don't continue
});

$s.register(sub ($request,$response,$last) {
$s.handler(sub ($request,$response) {
$response.status = 404;
'Registered sub2 called.'.say;
#this is never called!
$response.write('Registered Sub');
$response.close;
$last(False); #Continue if there is another
True; #Continue if there is another
});

$s.listen;
say "listening";
$s.block;
await $s.listen;
14 changes: 5 additions & 9 deletions examples/lib/HTTP/Server/Async/Plugins/Middleware/Hijack.pm6
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
class HTTP::Server::Async::Plugins::Middleware::Hijack {
has $.status is rw;
unit module HTTP::Server::Async::Plugins::Middleware::Hijack;

submethod BUILD(:$connection, :$request, :$response, :$tap) {
try {
$response.close("Hijacked.");
};
$!status = True;
}
};
sub hijack($request, $response) is export {
$response.close('Hijacked.');
False;
}

0 comments on commit 345383e

Please sign in to comment.