Debian Codegraph @

lib/HTTP/Server/Simple.pm

raw ◀ ▶
2 Debian patches touch this file
1 use strict;
2 use warnings;
3
4 package HTTP::Server::Simple;
5 use FileHandle;
6 use Socket;
7 use Carp;
•8 use IO::Select;
•9 use POSIX;
10
11 use vars qw($VERSION $bad_request_doc);
12 $VERSION = '0.52';
13
14 =head1 NAME
15
16 HTTP::Server::Simple - Lightweight HTTP server
17
18 =head1 SYNOPSIS
19
20 use warnings;
21 use strict;
22
23 use HTTP::Server::Simple;
24
25 my $server = HTTP::Server::Simple->new();
26 $server->run();
27
28 However, normally you will sub-class the HTTP::Server::Simple::CGI
29 module (see L<HTTP::Server::Simple::CGI>);
30
31 package Your::Web::Server;
32 use base qw(HTTP::Server::Simple::CGI);
33
34 sub handle_request {
35 my ($self, $cgi) = @_;
36
37 #... do something, print output to default
38 # selected filehandle...
39
40 }
41
42 1;
43
44 =head1 DESCRIPTION
45
46 This is a simple standalone HTTP server. By default, it doesn't thread
47 or fork. It does, however, act as a simple frontend which can be used
48 to build a standalone web-based application or turn a CGI into one.
49
50 It is possible to use L<Net::Server> classes to create forking,
51 pre-forking, and other types of more complicated servers; see
52 L</net_server>.
53
54 By default, the server traps a few signals:
55
56 =over
57
58 =item HUP
59
60 When you C<kill -HUP> the server, it lets the current request finish being
61 processed, then uses the C<restart> method to re-exec itself. Please note that
62 in order to provide restart-on-SIGHUP, HTTP::Server::Simple sets a SIGHUP
63 handler during initialisation. If your request handling code forks you need to
64 make sure you reset this or unexpected things will happen if somebody sends a
65 HUP to all running processes spawned by your app (e.g. by "kill -HUP <script>")
66
67 =item PIPE
68
69 If the server detects a broken pipe while writing output to the client,
70 it ignores the signal. Otherwise, a client closing the connection early
71 could kill the server.
72
73 =back
74
75 =head1 EXAMPLE
76
77 #!/usr/bin/perl
78 {
79 package MyWebServer;
80
81 use HTTP::Server::Simple::CGI;
82 use base qw(HTTP::Server::Simple::CGI);
83
84 my %dispatch = (
85 '/hello' => \&resp_hello,
86 # ...
87 );
88
89 sub handle_request {
90 my $self = shift;
91 my $cgi = shift;
92
93 my $path = $cgi->path_info();
94 my $handler = $dispatch{$path};
95
96 if (ref($handler) eq "CODE") {
97 print "HTTP/1.0 200 OK\r\n";
98 $handler->($cgi);
99
100 } else {
101 print "HTTP/1.0 404 Not found\r\n";
102 print $cgi->header,
103 $cgi->start_html('Not found'),
104 $cgi->h1('Not found'),
105 $cgi->end_html;
106 }
107 }
108
109 sub resp_hello {
110 my $cgi = shift; # CGI.pm object
111 return if !ref $cgi;
112
113 my $who = $cgi->param('name');
114
115 print $cgi->header,
116 $cgi->start_html("Hello"),
117 $cgi->h1("Hello $who!"),
118 $cgi->end_html;
119 }
120
121 }
122
123 # start the server on port 8080
124 my $pid = MyWebServer->new(8080)->background();
125 print "Use 'kill $pid' to stop server.\n";
126
127 =head1 METHODS
128
129 =head2 HTTP::Server::Simple->new($port, $family)
130
131 API call to start a new server. Does not actually start listening
132 until you call C<-E<gt>run()>. If omitted, C<$port> defaults to 8080,
133 and C<$family> defaults to L<Socket::AF_INET>.
134 The alternative domain is L<Socket::AF_INET6>.
135
136 =cut
137
138 sub new {
139 my ( $proto, $port, $family ) = @_;
140 my $class = ref($proto) || $proto;
141
142 if ( $class eq __PACKAGE__ ) {
143 require HTTP::Server::Simple::CGI;
144 return HTTP::Server::Simple::CGI->new( @_[ 1 .. $#_ ] );
145 }
146
147 my $self = {};
148 bless( $self, $class );
149 $self->port( $port || '8080' );
150 $self->family( $family || AF_INET );
151
152 return $self;
153 }
154
155
156 =head2 lookup_localhost
157
158 Looks up the local host's IP address, and returns it. For most hosts,
159 this is C<127.0.0.1>, or possibly C<::1>.
160
161 =cut
162
163 sub lookup_localhost {
164 my $self = shift;
165
166 my $local_sockaddr = getsockname( $self->stdio_handle );
167 my $local_family = sockaddr_family($local_sockaddr);
168
169 my ($host_err,$local_host, undef) = Socket::getnameinfo($local_sockaddr,0);
170 warn $host_err if ($host_err);
171 $self->host( $local_host || "localhost");
172
173 my ($addr_err,$local_addr,undef) = Socket::getnameinfo($local_sockaddr,Socket::NI_NUMERICHOST);
174 warn $addr_err if ($addr_err);
175 $self->{'local_addr'} = $local_addr
176 || (($local_family == AF_INET6) ? "::1" : "127.0.0.1");
177 }
178
179
180 =head2 port [NUMBER]
181
182 Takes an optional port number for this server to listen on.
183
184 Returns this server's port. (Defaults to 8080)
185
186 =cut
187
188 sub port {
189 my $self = shift;
190 $self->{'port'} = shift if (@_);
191 return ( $self->{'port'} );
192
193 }
194
195 =head2 family [NUMBER]
196
197 Takes an optional address family for this server to use. Valid values
198 are Socket::AF_INET and Socket::AF_INET6. All other values are silently
199 changed into Socket::AF_INET for backwards compatibility with previous
200 versions of the module.
201
202 Returns the address family of the present listening socket. (Defaults to
203 Socket::AF_INET.)
204
205 =cut
206
207 sub family {
208 my $self = shift;
209 if (@_) {
210 if ($_[0] == AF_INET || $_[0] == AF_INET6) {
211 $self->{'family'} = shift;
212 } else {
213 $self->{'family'} = AF_INET;
214 }
215 }
216 return ( $self->{'family'} );
217
218 }
219
220 =head2 host [address]
221
222 Takes an optional host address for this server to bind to.
223
224 Returns this server's bound address (if any). Defaults to C<undef>
225 (bind to all interfaces).
226
227 =cut
228
229 sub host {
230 my $self = shift;
231 $self->{'host'} = shift if (@_);
232 return ( $self->{'host'} );
233
234 }
235
236 =head2 background [ARGUMENTS]
237
238 Runs the server in the background, and returns the process ID of the
239 started process. Any arguments will be passed through to L</run>.
240
241 =cut
242
243 sub background {
244 my $self = shift;
•245
246 # set up a pipe so the child can tell the parent when it's ready
247 # to accept requests
248 my ($readfh, $writefh) = FileHandle::pipe;
249
250 my $child = fork;
251 croak "Can't fork: $!" unless defined($child);
•252
253 if ($child) { # parent
254 my $s = IO::Select->new;
255 $s->add($readfh);
256 my $now = time; my $left = 0;
257 my @ready;
258 while(not @ready and $left < 5) {
259 @ready = $s->can_read($left);
260 $left = time - $now;
261 }
262 die("child unresponsive for 5 seconds") if(not @ready);
263 my $response = <$readfh>;
264 chomp $response;
265 die("child is confused: answer '$response' != 'OK'")
266 if $response ne "OK";
267 return $child;
268 }
269
270 srand(); # after a fork, we need to reset the random seed
271 # or we'll get the same numbers in both branches
272 if ( $^O !~ /MSWin32/ ) {
273 require POSIX;
274 POSIX::setsid()
275 or croak "Can't start a new session: $!";
276 }
•277
278 $self->{_parent_handle} = $writefh;
279 $self->run(@_); # should never return
280 exit; # just to be sure
281 }
282
283 =head2 run [ARGUMENTS]
284
285 Run the server. If all goes well, this won't ever return, but it will
286 start listening for C<HTTP> requests. Any arguments passed to this
287 will be passed on to the underlying L<Net::Server> implementation, if
288 one is used (see L</net_server>).
289
290 =cut
291
292 my $server_class_id = 0;
293
294 use vars '$SERVER_SHOULD_RUN';
295 $SERVER_SHOULD_RUN = 1;
296
297 sub run {
298 my $self = shift;
299 my $server = $self->net_server;
300
301 local $SIG{CHLD} = 'IGNORE'; # reap child processes
302
303 # $pkg is generated anew for each invocation to "run"
304 # Just so we can use different net_server() implementations
305 # in different runs.
306 my $pkg = join '::', ref($self), "NetServer" . $server_class_id++;
307
308 no strict 'refs';
309 *{"$pkg\::process_request"} = $self->_process_request;
310
311 if ($server) {
312 require join( '/', split /::/, $server ) . '.pm';
313 *{"$pkg\::ISA"} = [$server];
314
315 # clear the environment before every request
316 require HTTP::Server::Simple::CGI;
317 *{"$pkg\::post_accept"} = sub {
318 HTTP::Server::Simple::CGI::Environment->setup_environment;
319 # $self->SUPER::post_accept uses the wrong super package
320 $server->can('post_accept')->(@_);
321 };
322 }
323 else {
324 $self->setup_listener;
325 $self->after_setup_listener();
326 *{"$pkg\::run"} = $self->_default_run;
327 }
•328 $self->_maybe_tell_parent();
329
330 local $SIG{HUP} = sub { $SERVER_SHOULD_RUN = 0; };
331
332 $pkg->run( port => $self->port, @_ );
333 }
334
335 =head2 net_server
336
337 User-overridable method. If you set it to a L<Net::Server> subclass,
338 that subclass is used for the C<run> method. Otherwise, a minimal
339 implementation is used as default.
340
341 =cut
342
343 sub net_server {undef}
344
345 sub _default_run {
346 my $self = shift;
347
348 # Default "run" closure method for a stub, minimal Net::Server instance.
349 return sub {
350 my $pkg = shift;
351
352 $self->print_banner;
353
354 while ($SERVER_SHOULD_RUN) {
355 local $SIG{PIPE} = 'IGNORE'; # If we don't ignore SIGPIPE, a
356 # client closing the connection before we
357 # finish sending will cause the server to exit
358 while ( accept( my $remote = new FileHandle, HTTPDaemon ) ) {
359 $self->stdio_handle($remote);
360 $self->lookup_localhost() unless ($self->host);
361 $self->accept_hook if $self->can("accept_hook");
362
363
364 *STDIN = $self->stdin_handle();
365 *STDOUT = $self->stdout_handle();
366 select STDOUT; # required for HTTP::Server::Simple::Recorder
367 # XXX TODO glasser: why?
368 $pkg->process_request;
369 close $remote;
370 }
371 }
372
373 # Got here? Time to restart, due to SIGHUP
374 $self->restart;
375 };
376 }
377
378 =head2 restart
379
380 Restarts the server. Usually called by a HUP signal, not directly.
381
382 =cut
383
384 sub restart {
385 my $self = shift;
386
387 close HTTPDaemon;
388
389 $SIG{CHLD} = 'DEFAULT';
390 wait;
391
392 ### if the standalone server was invoked with perl -I .. we will loose
393 ### those include dirs upon re-exec. So add them to PERL5LIB, so they
394 ### are available again for the exec'ed process --kane
395 use Config;
396 $ENV{PERL5LIB} .= join $Config{path_sep}, @INC;
397
398 # Server simple
399 # do the exec. if $0 is not executable, try running it with $^X.
400 exec {$0}( ( ( -x $0 ) ? () : ($^X) ), $0, @ARGV );
401 }
402
•403 # Read 1 character from STDIN with sysread. Returns '' on EOF, or undef on error.
404 sub _sysread_1 {
405 my $buff;
406 for (;;) {
407 my $r = sysread( STDIN, $buff, 1 );
408 return $buff // '' if defined $r;
409 # Normal perlio (read/print) handles EINTR for us. But we have to use sysread,
410 # which doesn't. We can get EINTR if we're in the middle of reading here, and
411 # handle a signal. As a library, we don't get to tell the application programmer
412 # they ought not to have any signal handlers. So we must retry on EINTR.
413 return undef if $! != EINTR;
414 }
415 }
416
417 sub _process_request {
418 my $self = shift;
419
420 # Create a callback closure that is invoked for each incoming request;
421 # the $self above is bound into the closure.
422 sub {
423
424 $self->stdio_handle(*STDIN) unless $self->stdio_handle;
425
426 # Default to unencoded, raw data out.
427 # if you're sending utf8 and latin1 data mixed, you may need to override this
428 binmode STDIN, ':raw';
429 binmode STDOUT, ':raw';
430
431 # The ternary operator below is to protect against a crash caused by IE
432 # Ported from Catalyst::Engine::HTTP (Originally by Jasper Krogh and Peter Edwards)
433 # ( http://dev.catalyst.perl.org/changeset/5195, 5221 )
434
435 my $remote_sockaddr = getpeername( $self->stdio_handle );
436 my $family = sockaddr_family($remote_sockaddr);
437
438 my ( $iport, $iaddr ) = $remote_sockaddr
439 ? ( ($family == AF_INET6) ? sockaddr_in6($remote_sockaddr)
440 : sockaddr_in($remote_sockaddr) )
441 : (undef,undef);
442
443 my $loopback = ($family == AF_INET6) ? "::1" : "127.0.0.1";
444 my $peeraddr = $loopback;
445 if ($iaddr) {
446 my ($host_err,$addr, undef) = Socket::getnameinfo($remote_sockaddr,Socket::NI_NUMERICHOST);
447 warn ($host_err) if $host_err;
448 $peeraddr = $addr || $loopback;
449 }
450
451
452 my ( $method, $request_uri, $proto ) = $self->parse_request;
453
454 unless ($self->valid_http_method($method) ) {
455 $self->bad_request;
456 return;
457 }
458
459 $proto ||= "HTTP/0.9";
460
461 my ( $file, $query_string )
462 = ( $request_uri =~ /([^?]*)(?:\?(.*))?/s ); # split at ?
463
464 $self->setup(
465 method => $method,
466 protocol => $proto,
467 query_string => ( defined($query_string) ? $query_string : '' ),
468 request_uri => $request_uri,
469 path => $file,
470 localname => $self->host,
471 localport => $self->port,
472 peername => $peeraddr,
473 peeraddr => $peeraddr,
474 peerport => $iport,
475 );
476
477 # HTTP/0.9 didn't have any headers (I think)
478 if ( $proto =~ m{HTTP/(\d(\.\d)?)$} and $1 >= 1 ) {
479
480 my $headers = $self->parse_headers
481 or do { $self->bad_request; return };
482
483 $self->headers($headers);
484
485 }
486
487 $self->post_setup_hook if $self->can("post_setup_hook");
488
489 $self->handler;
490 }
491 }
492
•493 sub _maybe_tell_parent {
494 # inform the parent process that we're ready, if applicable
495 my $self = shift;
496 my $handle = $self->{_parent_handle};
497 return if !$handle;
498 print $handle "OK\n";
499 close $handle;
500 delete $self->{_parent_handle};
501 }
502
503 =head2 stdio_handle [FILEHANDLE]
504
505 When called with an argument, sets the socket to the server to that arg.
506
507 Returns the socket to the server; you should only use this for actual socket-related
508 calls like C<getsockname>. If all you want is to read or write to the socket,
509 you should use C<stdin_handle> and C<stdout_handle> to get the in and out filehandles
510 explicitly.
511
512 =cut
513
514 sub stdio_handle {
515 my $self = shift;
516 $self->{'_stdio_handle'} = shift if (@_);
517 return $self->{'_stdio_handle'};
518 }
519
520 =head2 stdin_handle
521
522 Returns a filehandle used for input from the client. By default,
523 returns whatever was set with C<stdio_handle>, but a subclass could do
524 something interesting here.
525
526 =cut
527
528 sub stdin_handle {
529 my $self = shift;
530 return $self->stdio_handle;
531 }
532
533 =head2 stdout_handle
534
535 Returns a filehandle used for output to the client. By default,
536 returns whatever was set with C<stdio_handle>, but a subclass
537 could do something interesting here.
538
539 =cut
540
541 sub stdout_handle {
542 my $self = shift;
543 return $self->stdio_handle;
544 }
545
546 =head1 IMPORTANT SUB-CLASS METHODS
547
548 A selection of these methods should be provided by sub-classes of this
549 module.
550
551 =head2 handler
552
553 This method is called after setup, with no parameters. It should
554 print a valid, I<full> HTTP response to the default selected
555 filehandle.
556
557 =cut
558
559 sub handler {
560 my ($self) = @_;
561 if ( ref($self) ne __PACKAGE__ ) {
562 croak "do not call " . ref($self) . "::SUPER->handler";
563 }
564 else {
565 croak "handler called out of context";
566 }
567 }
568
569 =head2 setup(name =E<gt> $value, ...)
570
571 This method is called with a name =E<gt> value list of various things
572 to do with the request. This list is given below.
573
574 The default setup handler simply tries to call methods with the names
575 of keys of this list.
576
577 ITEM/METHOD Set to Example
578 ----------- ------------------ ------------------------
579 method Request Method "GET", "POST", "HEAD"
580 protocol HTTP version "HTTP/1.1"
581 request_uri Complete Request URI "/foobar/baz?foo=bar"
582 path Path part of URI "/foobar/baz"
583 query_string Query String undef, "foo=bar"
584 port Received Port 80, 8080
585 peername Remote name "200.2.4.5", "foo.com"
586 peeraddr Remote address "200.2.4.5", "::1"
587 peerport Remote port 42424
588 localname Local interface "localhost", "myhost.com"
589
590 =cut
591
592 sub setup {
593 my $self = shift;
594 while ( my ( $item, $value ) = splice @_, 0, 2 ) {
595 $self->$item($value) if $self->can($item);
596 }
597 }
598
599 =head2 headers([Header =E<gt> $value, ...])
600
601 Receives HTTP headers and does something useful with them. This is
602 called by the default C<setup()> method.
603
604 You have lots of options when it comes to how you receive headers.
605
606 You can, if you really want, define C<parse_headers()> and parse them
607 raw yourself.
608
609 Secondly, you can intercept them very slightly cooked via the
610 C<setup()> method, above.
611
612 Thirdly, you can leave the C<setup()> header as-is (or calling the
613 superclass C<setup()> for unknown request items). Then you can define
614 C<headers()> in your sub-class and receive them all at once.
615
616 Finally, you can define handlers to receive individual HTTP headers.
617 This can be useful for very simple SOAP servers (to name a
618 crack-fueled standard that defines its own special HTTP headers).
619
620 To do so, you'll want to define the C<header()> method in your subclass.
621 That method will be handed a (key,value) pair of the header name and the value.
622
623
624 =cut
625
626 sub headers {
627 my $self = shift;
628 my $headers = shift;
629
630 my $can_header = $self->can("header");
631 return unless $can_header;
632 while ( my ( $header, $value ) = splice @$headers, 0, 2 ) {
633 $self->header( $header => $value );
634 }
635 }
636
637 =head2 accept_hook
638
639 If defined by a sub-class, this method is called directly after an
640 accept happens. An accept_hook to add SSL support might look like this:
641
642 sub accept_hook {
643 my $self = shift;
644 my $fh = $self->stdio_handle;
645
646 $self->SUPER::accept_hook(@_);
647
648 my $newfh =
649 IO::Socket::SSL->start_SSL( $fh,
650 SSL_server => 1,
651 SSL_use_cert => 1,
652 SSL_cert_file => 'myserver.crt',
653 SSL_key_file => 'myserver.key',
654 )
655 or warn "problem setting up SSL socket: " . IO::Socket::SSL::errstr();
656
657 $self->stdio_handle($newfh) if $newfh;
658 }
659
660 =head2 post_setup_hook
661
662 If defined by a sub-class, this method is called after all setup has
663 finished, before the handler method.
664
665 =head2 print_banner
666
667 This routine prints a banner before the server request-handling loop
668 starts.
669
670 Methods below this point are probably not terribly useful to define
671 yourself in subclasses.
672
673 =cut
674
675 sub print_banner {
676 my $self = shift;
677
678 print( ref($self)
679 . ": You can connect to your server at "
680 . "http://localhost:"
681 . $self->port
682 . "/\n" );
683
684 }
685
686 =head2 parse_request
687
688 Parse the HTTP request line. Returns three values, the request
689 method, request URI and the protocol.
690
691 =cut
692
693 sub parse_request {
694 my $self = shift;
695 my $chunk;
•696 while ( length(my $buff = _sysread_1() // return undef) ) {
697 last if $buff eq "\n";
698 $chunk .= $buff;
699 }
700 defined($chunk) or return undef;
701 $_ = $chunk;
702
703 m/^(\w+)\s+(\S+)(?:\s+(\S+))?\r?$/;
704 my $method = $1 || '';
705 my $uri = $2 || '';
706 my $protocol = $3 || '';
707
708 # strip <scheme>://<host:port> out of HTTP/1.1 requests
709 $uri =~ s{^\w+://[^/]+/}{/};
710
711 return ( $method, $uri, $protocol );
712 }
713
714 =head2 parse_headers
715
716 Parses incoming HTTP headers from STDIN, and returns an arrayref of
717 C<(header =E<gt> value)> pairs. See L</headers> for possibilities on
718 how to inspect headers.
719
720 =cut
721
722 sub parse_headers {
723 my $self = shift;
724
725 my @headers;
726
727 my $chunk = '';
•728 while ( length(my $buff = _sysread_1() // return undef) ) {
729 if ( $buff eq "\n" ) {
730 $chunk =~ s/[\r\l\n\s]+$//;
731 if ( $chunk =~ /^([^()<>\@,;:\\"\/\[\]?={} \t]+):\s*(.*)/i ) {
732 push @headers, $1 => $2;
733 }
734 last if ( $chunk =~ /^$/ );
735 $chunk = '';
736 }
737 else { $chunk .= $buff }
738 }
739
740 return ( \@headers );
741 }
742
743 =head2 setup_listener
744
745 This routine binds the server to a port and interface.
746
747 =cut
748
749 sub setup_listener {
750 my $self = shift;
751
752 my $tcp = getprotobyname('tcp');
753 my $sockaddr;
754 socket( HTTPDaemon, $self->{'family'}, SOCK_STREAM, $tcp )
755 or croak "socket: $!";
756 setsockopt( HTTPDaemon, SOL_SOCKET, SO_REUSEADDR, pack( "l", 1 ) )
757 or warn "setsockopt: $!";
758
759 if ($self->host) { # Explicit listening address
760 my ($err, @res) = Socket::getaddrinfo($self->host, $self->port, { family => $self->{'family'}, socktype => SOCK_STREAM } );
761 warn "$err!"
762 if ($err);
763 # we're binding only to the first returned address in the requested family.
764 while ($a = shift(@res)) {
765 # Be certain on the address family.
766 # TODO Accept AF_UNSPEC, reject SITE-LOCAL
767 next unless ($self->{'family'} == $a->{'family'});
768
769 # Use the first plausible address.
770 $sockaddr = $a->{'addr'};
771 last;
772 }
773 }
774 else { # Use the wildcard address
775 $sockaddr = ($self->{'family'} == AF_INET6)
776 ? sockaddr_in6($self->port(), Socket::IN6ADDR_ANY)
777 : sockaddr_in($self->port(), INADDR_ANY);
778 }
779
780 bind( HTTPDaemon, $sockaddr)
781 or croak "bind to @{[$self->host||'*']}:@{[$self->port]}: $!";
782 listen( HTTPDaemon, SOMAXCONN ) or croak "listen: $!";
783 }
784
785
786 =head2 after_setup_listener
787
788 This method is called immediately after setup_listener. It's here just
789 for you to override.
790
791 =cut
792
793 sub after_setup_listener {
794 }
795
796 =head2 bad_request
797
798 This method should print a valid HTTP response that says that the
799 request was invalid.
800
801 =cut
802
803 $bad_request_doc = join "", <DATA>;
804
805 sub bad_request {
806 my $self = shift;
807
808 print "HTTP/1.0 400 Bad request\r\n"; # probably OK by now
809 print "Content-Type: text/html\r\nContent-Length: ",
810 length($bad_request_doc), "\r\n\r\n", $bad_request_doc;
811 }
812
813 =head2 valid_http_method($method)
814
815 Given a candidate HTTP method in $method, determine if it is valid.
816 Override if, for example, you'd like to do some WebDAV. The default
817 implementation only accepts C<GET>, C<POST>, C<HEAD>, C<PUT>, C<PATCH>,
818 C<DELETE> and C<OPTIONS>.
819
820 =cut
821
822 sub valid_http_method {
823 my $self = shift;
824 my $method = shift or return 0;
825 return $method =~ /^(?:GET|POST|HEAD|PUT|PATCH|DELETE|OPTIONS)$/;
826 }
827
828 =head1 AUTHOR
829
830 Best Practical Solutions, LLC E<lt>[email protected]<gt>
831
832 =head1 CONTRIBUTORS
833
834 Jesse Vincent, <[email protected]>. Original author.
835
836 Marcus Ramberg <[email protected]> contributed tests, cleanup, etc
837
838 Sam Vilain, <[email protected]> contributed the CGI.pm split-out and
839 header/setup API.
840
841 Example section by almut on perlmonks, suggested by Mark Fuller.
842
843 =head1 BUGS
844
845 There certainly are some. Please report them via rt.cpan.org
846
847 =head1 LICENSE
848
849 This software is Copyright (c) 2004-2015 Best Practical Solutions
850
851 This library is free software; you can redistribute it and/or modify
852 it under the same terms as Perl itself.
853
854 =cut
855
856 1;
857
858 __DATA__
859 <html>
860 <head>
861 <title>Bad Request</title>
862 </head>
863 <body>
864 <h1>Bad Request</h1>
865
866 <p>Your browser sent a request which this web server could not
867 grok.</p>
868 </body>
869 </html>