-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
fake_rest_api.pl
executable file
·62 lines (43 loc) · 1.07 KB
/
fake_rest_api.pl
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
#!/usr/bin/perl
{
package Server;
use HTTP::Server::Simple::CGI;
use Data::Dumper;
use base qw(HTTP::Server::Simple::CGI);
sub handle_request {
my $self = shift;
my $cgi = shift;
my $path = $cgi->path_info();
warn Dumper(\%ENV);
warn "path=($path)";
#my $body = $cgi->param('dog');
my $body = $cgi->param('POSTDATA');
warn "body=\n------\n$body\n";
warn "---------\n\n";
warn "params:\n";
my @p = $cgi->param;
foreach my $p (@p) {
warn "($p) -> (" . $cgi->param($p) . ")\n";
}
print "HTTP/1.0 200 OK\n\n{\"success\": true}";
=pod
if (ref($handler) eq "CODE") {
print "HTTP/1.0 200 OK\r\n";
$handler->($cgi);
} else {
print "HTTP/1.0 404 Not found\r\n";
print $cgi->header,
$cgi->start_html('Not found'),
$cgi->h1('Not found'),
$cgi->end_html;
}
=cut
}
}
my $pid = Server->new(5000)->run; #->background();
warn "running on port 5000; pid=$pid\n";
sub parse_headers {
my $foo = shift;
warn "?????????????????????????\n" . Dumper($foo);
return;
}