X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=tests%2FHTTPServer.pm;h=627c10283f539c0af44a5554dc13bcffd2e15d60;hb=30391ad9b479dfb0538c85c86976ab7fa24bacc2;hp=e3c38e6f5f02c31a580813591b6e21a2726a6dc2;hpb=d8c11a82ca9e8fab6689b53dc12199da4cc6058d;p=wget diff --git a/tests/HTTPServer.pm b/tests/HTTPServer.pm index e3c38e6f..627c1028 100644 --- a/tests/HTTPServer.pm +++ b/tests/HTTPServer.pm @@ -26,7 +26,8 @@ sub run { my $con = $self->accept(); print STDERR "Accepted a new connection\n" if $log; while (my $req = $con->get_request) { - my $url_path = $req->url->path; + #my $url_path = $req->url->path; + my $url_path = $req->url->as_string; if ($url_path =~ m{/$}) { # append 'index.html' $url_path .= 'index.html'; } @@ -67,6 +68,9 @@ sub send_response { if (exists $url_rec->{'auth_method'}) { ($send_content, $code, $msg, $headers) = $self->handle_auth($req, $url_rec); + } elsif (!$self->verify_request_headers ($req, $url_rec)) { + ($send_content, $code, $msg, $headers) = + ('', 400, 'Mismatch on expected headers', {}); } else { ($code, $msg) = @{$url_rec}{'code', 'msg'}; $headers = $url_rec->{headers}; @@ -119,7 +123,7 @@ sub send_response { next; } # fill in content - $content = $self->_substitute_port($content); + $content = $self->_substitute_port($content) if defined $content; $resp->content($content); print STDERR "HTTP::Response with content: \n", $resp->as_string if $log; } @@ -209,6 +213,23 @@ sub verify_auth_basic { } } +sub verify_request_headers { + my ($self, $req, $url_rec) = @_; + + return 1 unless exists $url_rec->{'request_headers'}; + for my $hdrname (keys %{$url_rec->{'request_headers'}}) { + my $rhdr = $req->header ($hdrname); + my $ehdr = $url_rec->{'request_headers'}{$hdrname}; + unless (defined $rhdr && $rhdr =~ $ehdr) { + $rhdr = '' unless defined $rhdr; + print STDERR "\n*** Mismatch on $hdrname: $rhdr =~ $ehdr\n"; + return undef; + } + } + + return 1; +} + sub _substitute_port { my $self = shift; my $ret = shift;