]> sjero.net Git - wget/blobdiff - tests/HTTPServer.pm
Heed cookies from 401s.
[wget] / tests / HTTPServer.pm
index 5252b5b8c7c89193857c23cde3eefe8934675cdc..627c10283f539c0af44a5554dc13bcffd2e15d60 100644 (file)
@@ -68,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};
@@ -120,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;
     }
@@ -210,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;