1#!/usr/bin/env perl 2BEGIN { 3 # add current source dir to the include-path 4 # we need this for make distcheck 5 (my $srcdir = $0) =~ s,/[^/]+$,/,; 6 unshift @INC, $srcdir; 7} 8 9use strict; 10use IO::Socket; 11use Test::More tests => 13; 12use LightyTest; 13 14my $tf = LightyTest->new(); 15my $t; 16 17$tf->{CONFIGFILE} = 'lighttpd.conf'; 18 19ok($tf->start_proc == 0, "Starting lighttpd") or die(); 20 21## check if If-Modified-Since, If-None-Match works 22 23$t->{REQUEST} = ( <<EOF 24GET / HTTP/1.0 25If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT 26EOF 27 ); 28$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 29ok($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since'); 30 31$t->{REQUEST} = ( <<EOF 32GET / HTTP/1.0 33If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo 34EOF 35 ); 36$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Last-Modified' => ''} ]; 37ok($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since, comment'); 38 39my $now = $t->{date}; 40 41$t->{REQUEST} = ( <<EOF 42GET / HTTP/1.0 43If-Modified-Since: $now 44EOF 45 ); 46$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ]; 47ok($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since'); 48 49$t->{REQUEST} = ( <<EOF 50GET / HTTP/1.0 51If-Modified-Since: $now; foo 52EOF 53 ); 54$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ]; 55ok($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since, comment'); 56 57$t->{REQUEST} = ( <<EOF 58GET / HTTP/1.0 59If-None-Match: foo 60EOF 61 ); 62$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => ''} ]; 63ok($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match'); 64 65my $etag = $t->{etag}; 66 67$t->{REQUEST} = ( <<EOF 68GET / HTTP/1.0 69If-None-Match: $etag 70EOF 71 ); 72$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ]; 73ok($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match'); 74 75$t->{REQUEST} = ( <<EOF 76GET / HTTP/1.0 77If-None-Match: $etag 78If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo 79EOF 80 ); 81$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 82ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + old Last-Modified'); 83 84$t->{REQUEST} = ( <<EOF 85GET / HTTP/1.0 86If-None-Match: $etag 87If-Modified-Since: $now; foo 88EOF 89 ); 90$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ]; 91ok($tf->handle_http($t) == 0, 'Conditional GET - ETag, Last-Modified + comment'); 92 93$t->{REQUEST} = ( <<EOF 94GET / HTTP/1.0 95If-None-Match: Foo 96If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo 97EOF 98 ); 99$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 100ok($tf->handle_http($t) == 0, 'Conditional GET - old ETAG + old Last-Modified'); 101 102$t->{REQUEST} = ( <<EOF 103GET / HTTP/1.0 104If-None-Match: $etag 105If-Modified-Since: $now foo 106EOF 107 ); 108$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 412 } ]; 109ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + Last-Modified + overlong timestamp'); 110 111$t->{REQUEST} = ( <<EOF 112GET / HTTP/1.0 113If-None-Match: $etag 114Host: etag.example.org 115EOF 116 ); 117$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 118ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + disabled etags on server side'); 119 120ok($tf->stop_proc == 0, "Stopping lighttpd"); 121 122