summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2021-03-24 21:03:07 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2021-03-24 21:03:07 +0000
commit5a0e7c728e1a13ef7bc9968550aa9e8cf78b5857 (patch)
tree7ac627b5962ad69418607e90bf10fb31d695d72e /regress
parent084ce2367806d4666375adbdd04db5eb762866cf (diff)
test HEAD requests, from niklas@
Diffstat (limited to 'regress')
-rw-r--r--regress/usr.sbin/relayd/args-http-head-get.pl45
-rw-r--r--regress/usr.sbin/relayd/funcs.pl20
2 files changed, 56 insertions, 9 deletions
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
index 00000000000..3176d05e33f
--- /dev/null
+++ b/regress/usr.sbin/relayd/args-http-head-get.pl
@@ -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;
diff --git a/regress/usr.sbin/relayd/funcs.pl b/regress/usr.sbin/relayd/funcs.pl
index 27f77a60a19..b7e4985ec21 100644
--- a/regress/usr.sbin/relayd/funcs.pl
+++ b/regress/usr.sbin/relayd/funcs.pl
@@ -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 {