Skip to content

Commit cce4cac

Browse files
committed
Add PING HTTP Method
1 parent 6c66a7a commit cce4cac

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

META.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ requires:
2222
Digest::SHA1: '2'
2323
HTTP::Easy: '0.03'
2424
JSON::XS: '3'
25-
version: '1.9999'
25+
version: '1.99992'

lib/AnyEvent/HTTP/Server.pm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ AnyEvent::HTTP::Server - AnyEvent HTTP/1.1 Server
77
=cut
88

99
BEGIN{
10-
our $VERSION = '1.99991';
10+
our $VERSION = '1.99992';
1111
}
1212

1313
#use common::sense;
@@ -410,6 +410,14 @@ sub incoming {
410410
$self->{active_requests}--;
411411
$ixx = $pos + $h{'content-length'};
412412
}
413+
elsif ( $method eq 'PING' ) {
414+
my ( $header_str, $content ) = ref $self->{ping_sub} eq 'CODE' ? $self->{ping_sub}->() : ('200 OK', 'Pong '.time()."\n");
415+
my $str = "HTTP/1.1 $header_str${LF}Connection:close${LF}Content-Type:text/plain${LF}Content-Length:".length($content)."${LF}${LF}".$content;
416+
$write->(\$str);
417+
$write->(\undef);
418+
$self->{active_requests}--;
419+
$ixx = $pos + $h{'content-length'};
420+
}
413421
elsif ( $self->{ping} and $method eq "GET" and $uri =~ m{^/ping( \Z | \? )}sox ) {
414422
my ( $header_str, $content ) = ref $self->{ping_sub} eq 'CODE' ? $self->{ping_sub}->() : ('200 OK', 'Pong');
415423
my $str = "HTTP/1.1 $header_str${LF}Connection:close${LF}Content-Type:text/plain${LF}Content-Length:".length($content)."${LF}${LF}".$content;

0 commit comments

Comments
 (0)