Module: monitoring-plugins
    Branch: master
    Commit: c256af44fb23a4749faa5f3fce167a9d9a4367d7
    Author: Sven Nierlein <s...@nierlein.de>
 Committer: Sven Nierlein <s...@nierlein.org>
      Date: Thu Dec 22 14:06:08 2022 +0100
       URL: 
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=c256af4

check_http/check_curl: add chunked encoding test

---

 plugins/tests/check_curl.t | 18 +++++++++++++++++-
 plugins/tests/check_http.t | 18 +++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t
index aa72ef6..86bfb53 100755
--- a/plugins/tests/check_curl.t
+++ b/plugins/tests/check_curl.t
@@ -21,7 +21,7 @@ use FindBin qw($Bin);
 
 $ENV{'LC_TIME'} = "C";
 
-my $common_tests = 72;
+my $common_tests = 74;
 my $ssl_only_tests = 8;
 # Check that all dependent modules are available
 eval "use HTTP::Daemon 6.01;";
@@ -200,6 +200,17 @@ sub run_server {
                                $c->send_basic_header;
                                $c->send_crlf;
                                $c->send_response(HTTP::Response->new( 200, 
'OK', undef, $r->header ('Host')));
+                               } elsif ($r->url->path eq "/chunked") {
+                                       $c->send_basic_header;
+                                       $c->send_header('Transfer-Encoding', 
"chunked");
+                                       $c->send_crlf;
+                                       my $chunks = ["chunked", "encoding", 
"test\n"];
+                                       $c->send_response(HTTP::Response->new( 
200, 'OK', undef, sub {
+                                               my $chunk = shift @{$chunks};
+                                               return unless $chunk;
+                                               sleep(1);
+                                               return($chunk);
+                                       }));
                        } else {
                                $c->send_error(HTTP::Status->RC_FORBIDDEN);
                        }
@@ -508,4 +519,9 @@ sub run_common_tests {
        };
        is( $@, "", $cmd );
 
+       $cmd = "$command -u /chunked -s 'chunkedencodingtest'";
+       eval {
+               $result = NPTest->testCmd( $cmd, 5 );
+       };
+       is( $@, "", $cmd );
 }
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index ea11b2a..132c665 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -12,7 +12,7 @@ use FindBin qw($Bin);
 
 $ENV{'LC_TIME'} = "C";
 
-my $common_tests = 70;
+my $common_tests = 72;
 my $virtual_port_tests = 8;
 my $ssl_only_tests = 12;
 # Check that all dependent modules are available
@@ -190,6 +190,17 @@ sub run_server {
                                        $c->send_basic_header;
                                        $c->send_crlf;
                                        $c->send_response(HTTP::Response->new( 
200, 'OK', undef, $r->header ('Host')));
+                               } elsif ($r->url->path eq "/chunked") {
+                                       $c->send_basic_header;
+                                       $c->send_header('Transfer-Encoding', 
"chunked");
+                                       $c->send_crlf;
+                                       my $chunks = ["chunked", "encoding", 
"test\n"];
+                                       $c->send_response(HTTP::Response->new( 
200, 'OK', undef, sub {
+                                               my $chunk = shift @{$chunks};
+                                               return unless $chunk;
+                                               sleep(1);
+                                               return($chunk);
+                                       }));
                                } else {
                                        
$c->send_error(HTTP::Status->RC_FORBIDDEN);
                                }
@@ -497,4 +508,9 @@ sub run_common_tests {
        };
        is( $@, "", $cmd );
 
+       $cmd = "$command -u /chunked -s 'chunkedencodingtest'";
+       eval {
+               $result = NPTest->testCmd( $cmd, 5 );
+       };
+       is( $@, "", $cmd );
 }

Reply via email to