summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/t/80yaml-merge.t
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /web/server/h2o/libh2o/t/80yaml-merge.t
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/server/h2o/libh2o/t/80yaml-merge.t')
-rw-r--r--web/server/h2o/libh2o/t/80yaml-merge.t82
1 files changed, 82 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/t/80yaml-merge.t b/web/server/h2o/libh2o/t/80yaml-merge.t
new file mode 100644
index 000000000..55cd3911d
--- /dev/null
+++ b/web/server/h2o/libh2o/t/80yaml-merge.t
@@ -0,0 +1,82 @@
+use strict;
+use warnings;
+use Digest::MD5 qw(md5_hex);
+use File::Temp qw(tempdir);
+use Net::EmptyPort qw(check_port);
+use Test::More;
+use t::Util;
+
+plan skip_all => 'mruby support is off'
+ unless server_features()->{mruby};
+
+plan skip_all => 'nc not found'
+ unless prog_exists('nc');
+
+my @ports = empty_ports(3);
+
+my $tempdir = tempdir(CLEANUP => 1);
+
+{ # create configuration file
+ open my $fh, ">", "$tempdir/h2o.conf"
+ or die "failed to create file:$tempdir/h2o.conf:$!";
+ print $fh <<"EOT";
+hosts:
+ host1: \&default
+ listen: $ports[0]
+ paths:
+ /:
+ mruby.handler: |
+ Proc.new do |env|
+ [200, {}, [env["SERVER_NAME"]]]
+ end
+ host2:
+ listen: $ports[1]
+ <<: *default
+ host3:
+ <<: *default
+ listen: $ports[2]
+EOT
+};
+
+my $guard = spawn_server(
+ argv => [ bindir() . "/h2o", "-c", "$tempdir/h2o.conf" ],
+ is_ready => sub {
+ for (@ports) {
+ return unless check_port($_);
+ }
+ return 1;
+ },
+);
+
+subtest "port1" => sub {
+ subtest "no-host" => sub {
+ my $resp = `(echo "GET / HTTP/1.0"; echo) | nc 127.0.0.1 $ports[0] 2>&1`;
+ like $resp, qr{^HTTP/1\.[0-9]+ 200 OK\r\n}s;
+ like $resp, qr{\r\n\r\nhost1$}s;
+ };
+ subtest "host=host2" => sub {
+ my $resp = `(echo "GET / HTTP/1.0"; echo "Host: host2"; echo) | nc 127.0.0.1 $ports[0] 2>&1`;
+ like $resp, qr{^HTTP/1\.[0-9]+ 200 OK\r\n}s;
+ like $resp, qr{\r\n\r\nhost2$}s;
+ };
+ subtest "host=host3" => sub {
+ # host3 is not listening on the default port
+ my $resp = `(echo "GET / HTTP/1.0"; echo) | nc 127.0.0.1 $ports[0] 2>&1`;
+ like $resp, qr{^HTTP/1\.[0-9]+ 200 OK\r\n}s;
+ like $resp, qr{\r\n\r\nhost1$}s;
+ };
+};
+
+subtest "port2" => sub {
+ my $resp = `(echo "GET / HTTP/1.0"; echo) | nc 127.0.0.1 $ports[1] 2>&1`;
+ like $resp, qr{^HTTP/1\.[0-9]+ 200 OK\r\n}s;
+ like $resp, qr{\r\n\r\nhost2$}s;
+};
+
+subtest "port3" => sub {
+ my $resp = `(echo "GET / HTTP/1.0"; echo) | nc 127.0.0.1 $ports[2] 2>&1`;
+ like $resp, qr{^HTTP/1\.[0-9]+ 200 OK\r\n}s;
+ like $resp, qr{\r\n\r\nhost3$}s;
+};
+
+done_testing;