-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
examples/lib/HTTP/Server/Async/Plugins/Middleware/Hijack.pm6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |