test HEAD requests, from niklas@
authorbenno <benno@openbsd.org>
Wed, 24 Mar 2021 21:03:06 +0000 (21:03 +0000)
committerbenno <benno@openbsd.org>
Wed, 24 Mar 2021 21:03:06 +0000 (21:03 +0000)
regress/usr.sbin/relayd/args-http-head-get.pl [new file with mode: 0644]
regress/usr.sbin/relayd/funcs.pl

diff --git a/regress/usr.sbin/relayd/args-http-head-get.pl b/regress/usr.sbin/relayd/args-http-head-get.pl
new file mode 100644 (file)
index 0000000..3176d05
--- /dev/null
@@ -0,0 +1,45 @@
+use strict;
+use warnings;
+
+my $payload_len = 64;
+our %args = (
+    client => {
+       func => sub {
+           my $self = shift;
+           my @request_stream = split("\n", <<"EOF", -1);
+HEAD http://foo.bar/$payload_len HTTP/1.1
+
+EOF
+           pop @request_stream;
+           print map { "$_\r\n" } @request_stream;
+           print STDERR map { ">>> $_\n" } @request_stream;
+           $self->{method} = 'HEAD';
+           http_response($self, $payload_len);
+           @request_stream = split("\n", <<"EOF", -1);
+GET http://foo.bar/$payload_len HTTP/1.1
+
+EOF
+           pop @request_stream;
+           print map { "$_\r\n" } @request_stream;
+           print STDERR map { ">>> $_\n" } @request_stream;
+           $self->{method} = 'GET';
+           http_response($self, $payload_len);
+       },
+       http_vers => ["1.1"],
+       nocheck => 1,
+    },
+    relayd => {
+       protocol => [ "http",
+           "match request path log \"*\"",
+       ],
+       loggrep => {
+           qr/, done, \[http:\/\/foo.bar\/$payload_len\] HEAD; \[http:\/\/foo.bar\/$payload_len\] GET/ => 1,
+       },
+    },
+    server => {
+       func => \&http_server,
+       nocheck => 1,
+    },
+);
+
+1;
index 27f77a6..b7e4985 100644 (file)
@@ -1,4 +1,4 @@
-#      $OpenBSD: funcs.pl,v 1.23 2017/07/14 14:41:03 bluhm Exp $
+#      $OpenBSD: funcs.pl,v 1.24 2021/03/24 21:03:06 benno Exp $
 
 # Copyright (c) 2010-2017 Alexander Bluhm <bluhm@openbsd.org>
 #
@@ -280,12 +280,14 @@ sub http_response {
                        }
                }
        }
-       if ($chunked) {
-               read_chunked($self);
-       } else {
-               undef $len unless defined($vers) && $vers eq "1.1";
-               read_char($self, $len)
-                   if $method eq "GET";
+       if ($method ne 'HEAD') {
+               if ($chunked) {
+                       read_chunked($self);
+               } else {
+                       undef $len unless defined($vers) && $vers eq "1.1";
+                       read_char($self, $len)
+                           if $method eq "GET";
+               }
        }
 }
 
@@ -423,7 +425,7 @@ sub http_server {
                        print STDERR "<<< $_\n";
                        ($method, $url, $vers) = m{^(\w+) (.*) HTTP/(1\.[01])$}
                            or die ref($self), " http request not ok";
-                       $method =~ /^(GET|PUT)$/
+                       $method =~ /^(GET|HEAD|PUT)$/
                            or die ref($self), " unknown method: $method";
                        ($len, my @chunks) = $url =~ /(\d+)/g;
                        $len = [ $len, @chunks ] if @chunks;
@@ -449,7 +451,7 @@ sub http_server {
 
                my @response = ("HTTP/$vers 200 OK");
                $len = defined($len) ? $len : scalar(split /|/,$url);
-               if ($vers eq "1.1" && $method eq "GET") {
+               if ($vers eq "1.1" && $method =~ /^(GET|HEAD)$/) {
                        if (ref($len) eq 'ARRAY') {
                                push @response, "Transfer-Encoding: chunked";
                        } else {