-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsaofs.pl
More file actions
64 lines (45 loc) · 1.44 KB
/
saofs.pl
File metadata and controls
64 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
##
## simple openframe server
##
use lib './lib';
use strict;
use warnings;
use Pipeline;
use HTTP::Daemon;
use Data::Dumper;
use OpenFrame::Segment::HTTP::Request;
use OpenFrame::Segment::ContentLoader;
my $d = HTTP::Daemon->new( LocalPort => '8080', Reuse => 1);
die $! unless $d;
print "server running at http://localhost:8080/\n";
## wait for connections
while(my $c = $d->accept()) {
## get requests of the connection
while(my $r = $c->get_request) {
## create a new Pipeline object
my $pipeline = Pipeline->new();
##
## create the segments
##
## the http request segment turns an HTTP request into something we
## can deal with...
my $hr = OpenFrame::Segment::HTTP::Request->new();
## the content loader simply loads the file that we are
## looking for based on the URI
my $cl = OpenFrame::Segment::ContentLoader->new()
->directory("./webpages");
## add the two segments to the pipeline
$pipeline->add_segment( $hr, $cl );
## create a new store
my $store = Pipeline::Store::Simple->new();
## add the request into the store and then add the store to the pipeline
$pipeline->store( $store->set( $r ) );
## dispatch the pipeline
$pipeline->dispatch();
## get the response out
my $response = $pipeline->store->get('HTTP::Response');
## send it to the client.
$c->send_response( $response );
}
}