~yozik04/nginx/rtmp

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/t/016-resp-header.t

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-02-15 03:05:42 UTC
  • mfrom: (4.3.10 sid)
  • Revision ID: package-import@ubuntu.com-20140215030542-71ubtowl24vf7nfn
Tags: 1.4.5-1ubuntu1
* Resynchronise with Debian (LP: #1280511).  Remaining changes:
  - debian/patches/ubuntu-branding.patch:
    + Add Ubuntu branding to server_tokens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# vim:set ft= ts=4 sw=4 et fdm=marker:
2
2
 
3
3
use lib 'lib';
4
 
use Test::Nginx::Socket;
 
4
use Test::Nginx::Socket::Lua;
5
5
 
6
6
#worker_connections(1014);
7
7
#master_process_enabled(1);
9
9
 
10
10
repeat_each(2);
11
11
 
12
 
plan tests => repeat_each() * (blocks() * 3 + 2);
 
12
plan tests => repeat_each() * (blocks() * 3 + 10);
13
13
 
14
14
#no_diff();
15
15
no_long_string();
626
626
    GET /lua
627
627
--- response_headers
628
628
Cache-Control: private, no-store
629
 
--- response_body
630
 
Cache-Control: private; no-store
 
629
--- response_body_like chop
 
630
^Cache-Control: private[;,] no-store$
631
631
 
632
632
 
633
633
 
658
658
            ngx.header.cache_control = { "private", "no-store" }
659
659
            ngx.header.cache_control = { "no-cache", "blah", "foo" }
660
660
            ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
661
 
            ngx.say("Cache-Control: ", table.concat(ngx.header.cache_control, "; "))
 
661
            ngx.say("Cache-Control: ", table.concat(ngx.header.cache_control, ", "))
662
662
        ';
663
663
    }
664
664
--- request
665
665
    GET /lua
666
666
--- response_headers
667
667
Cache-Control: no-cache, blah, foo
668
 
--- response_body
669
 
Cache-Control: no-cache; blah; foo
670
 
Cache-Control: no-cache; blah; foo
 
668
--- response_body_like chop
 
669
^Cache-Control: no-cache[;,] blah[;,] foo
 
670
Cache-Control: no-cache[;,] blah[;,] foo$
671
671
 
672
672
 
673
673
 
854
854
--- no_error_log
855
855
[error]
856
856
 
 
857
 
 
858
 
 
859
=== TEST 43: set multiple response header
 
860
--- config
 
861
    location /read {
 
862
        content_by_lua '
 
863
            for i = 1, 50 do
 
864
                ngx.header["X-Direct-" .. i] = "text/my-plain-" .. i;
 
865
            end
 
866
 
 
867
            ngx.say(ngx.header["X-Direct-50"]);
 
868
        ';
 
869
    }
 
870
--- request
 
871
GET /read
 
872
--- response_body
 
873
text/my-plain-50
 
874
--- no_error_log
 
875
[error]
 
876
 
 
877
 
 
878
 
 
879
=== TEST 44: set multiple response header and then reset and then clear
 
880
--- config
 
881
    location /read {
 
882
        content_by_lua '
 
883
            for i = 1, 50 do
 
884
                ngx.header["X-Direct-" .. i] = "text/my-plain-" .. i;
 
885
            end
 
886
 
 
887
            for i = 1, 50 do
 
888
                ngx.header["X-Direct-" .. i] = "text/my-plain"
 
889
            end
 
890
 
 
891
            for i = 1, 50 do
 
892
                ngx.header["X-Direct-" .. i] = nil
 
893
            end
 
894
 
 
895
            ngx.say("ok");
 
896
        ';
 
897
    }
 
898
--- request
 
899
GET /read
 
900
--- response_body
 
901
ok
 
902
--- no_error_log
 
903
[error]
 
904
 
 
905
 
 
906
 
 
907
=== TEST 45: set response content-type header for multiple times
 
908
--- config
 
909
    location /read {
 
910
        content_by_lua '
 
911
            ngx.header.content_type = "text/my-plain";
 
912
            ngx.header.content_type = "text/my-plain-2";
 
913
            ngx.say("Hi");
 
914
        ';
 
915
    }
 
916
--- request
 
917
GET /read
 
918
--- response_headers
 
919
Content-Type: text/my-plain-2
 
920
--- response_body
 
921
Hi
 
922
 
 
923
 
 
924
 
 
925
=== TEST 46: set Last-Modified response header for multiple times
 
926
--- config
 
927
    location /read {
 
928
        content_by_lua '
 
929
            ngx.header.last_modified = ngx.http_time(1290079655)
 
930
            ngx.header.last_modified = ngx.http_time(1290079654)
 
931
            ngx.say("ok");
 
932
        ';
 
933
    }
 
934
--- request
 
935
GET /read
 
936
--- response_headers
 
937
Last-Modified: Thu, 18 Nov 2010 11:27:34 GMT
 
938
--- response_body
 
939
ok
 
940
 
 
941
 
 
942
 
 
943
=== TEST 47: set Last-Modified response header and then clear
 
944
--- config
 
945
    location /read {
 
946
        content_by_lua '
 
947
            ngx.header.last_modified = ngx.http_time(1290079655)
 
948
            ngx.header.last_modified = nil
 
949
            ngx.say("ok");
 
950
        ';
 
951
    }
 
952
--- request
 
953
GET /read
 
954
--- response_headers
 
955
!Last-Modified
 
956
--- response_body
 
957
ok
 
958
 
 
959
 
 
960
 
 
961
=== TEST 48: github #20: segfault caused by the nasty optimization in the nginx core (write)
 
962
--- config
 
963
    location = /t/ {
 
964
        header_filter_by_lua '
 
965
            ngx.header.foo = 1
 
966
        ';
 
967
        proxy_pass http://127.0.0.1:$server_port;
 
968
    }
 
969
--- request
 
970
GET /t
 
971
--- more_headers
 
972
Foo: bar
 
973
Bah: baz
 
974
--- response_headers
 
975
Location: http://localhost:$ServerPort/t/
 
976
--- response_body_like: 301 Moved Permanently
 
977
--- error_code: 301
 
978
--- no_error_log
 
979
[error]
 
980
 
 
981
 
 
982
 
 
983
=== TEST 49: github #20: segfault caused by the nasty optimization in the nginx core (read)
 
984
--- config
 
985
    location = /t/ {
 
986
        header_filter_by_lua '
 
987
            local v = ngx.header.foo
 
988
        ';
 
989
        proxy_pass http://127.0.0.1:$server_port;
 
990
    }
 
991
--- request
 
992
GET /t
 
993
--- more_headers
 
994
Foo: bar
 
995
Bah: baz
 
996
--- response_body_like: 301 Moved Permanently
 
997
--- response_headers
 
998
Location: http://localhost:$ServerPort/t/
 
999
--- error_code: 301
 
1000
--- no_error_log
 
1001
[error]
 
1002
 
 
1003
 
 
1004
 
 
1005
=== TEST 50: github #20: segfault caused by the nasty optimization in the nginx core (read Location)
 
1006
--- config
 
1007
    location = /t/ {
 
1008
        header_filter_by_lua '
 
1009
            ngx.header.Foo = ngx.header.location
 
1010
        ';
 
1011
        proxy_pass http://127.0.0.1:$server_port;
 
1012
    }
 
1013
--- request
 
1014
GET /t
 
1015
--- more_headers
 
1016
Foo: bar
 
1017
Bah: baz
 
1018
--- response_headers
 
1019
Location: http://localhost:$ServerPort/t/
 
1020
Foo: /t/
 
1021
--- response_body_like: 301 Moved Permanently
 
1022
--- error_code: 301
 
1023
--- no_error_log
 
1024
[error]
 
1025
 
 
1026
 
 
1027
 
 
1028
=== TEST 51: github #20: segfault caused by the nasty optimization in the nginx core (set Foo and read Location)
 
1029
--- config
 
1030
    location = /t/ {
 
1031
        header_filter_by_lua '
 
1032
            ngx.header.Foo = 3
 
1033
            ngx.header.Foo = ngx.header.location
 
1034
        ';
 
1035
        proxy_pass http://127.0.0.1:$server_port;
 
1036
    }
 
1037
--- request
 
1038
GET /t
 
1039
--- more_headers
 
1040
Foo: bar
 
1041
Bah: baz
 
1042
--- response_headers
 
1043
Location: http://localhost:$ServerPort/t/
 
1044
Foo: /t/
 
1045
--- response_body_like: 301 Moved Permanently
 
1046
--- error_code: 301
 
1047
--- no_error_log
 
1048
[error]
 
1049
 
 
1050
 
 
1051
 
 
1052
=== TEST 52: case sensitive cache-control header
 
1053
--- config
 
1054
    location /lua {
 
1055
        content_by_lua '
 
1056
            ngx.header["cache-Control"] = "private"
 
1057
            ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
 
1058
        ';
 
1059
    }
 
1060
--- request
 
1061
    GET /lua
 
1062
--- raw_response_headers_like chop
 
1063
cache-Control: private
 
1064
--- response_body
 
1065
Cache-Control: private
 
1066
 
 
1067
 
 
1068
 
 
1069
=== TEST 53: clear Cache-Control when there was no Cache-Control
 
1070
--- config
 
1071
    location /lua {
 
1072
        content_by_lua '
 
1073
            ngx.header["Cache-Control"] = nil
 
1074
            ngx.say("Cache-Control: ", ngx.var.sent_http_cache_control)
 
1075
        ';
 
1076
    }
 
1077
--- request
 
1078
    GET /lua
 
1079
--- raw_response_headers_unlike eval
 
1080
qr/Cache-Control/i
 
1081
--- response_body
 
1082
Cache-Control: nil
 
1083
 
 
1084
 
 
1085
 
 
1086
=== TEST 54: set response content-type header
 
1087
--- config
 
1088
    location /read {
 
1089
        content_by_lua '
 
1090
            local s = "content_type"
 
1091
            local v = ngx.header[s]
 
1092
            ngx.say("s = ", s)
 
1093
        ';
 
1094
    }
 
1095
--- request
 
1096
GET /read
 
1097
--- response_body
 
1098
s = content_type
 
1099
 
 
1100
--- no_error_log
 
1101
[error]
 
1102
 
 
1103
 
 
1104
 
 
1105
=== TEST 55: set a number header name
 
1106
--- config
 
1107
    location /lua {
 
1108
        content_by_lua '
 
1109
            ngx.header[32] = "private"
 
1110
            ngx.say("32: ", ngx.var.sent_http_32)
 
1111
        ';
 
1112
    }
 
1113
--- request
 
1114
    GET /lua
 
1115
--- response_headers
 
1116
32: private
 
1117
--- response_body
 
1118
32: private
 
1119
--- no_error_log
 
1120
[error]
 
1121
 
 
1122
 
 
1123
 
 
1124
=== TEST 56: set a number header name (in a table value)
 
1125
--- config
 
1126
    location /lua {
 
1127
        content_by_lua '
 
1128
            ngx.header.foo = {32}
 
1129
            ngx.say("foo: ", ngx.var.sent_http_foo)
 
1130
        ';
 
1131
    }
 
1132
--- request
 
1133
    GET /lua
 
1134
--- response_headers
 
1135
foo: 32
 
1136
--- response_body
 
1137
foo: 32
 
1138
--- no_error_log
 
1139
[error]
 
1140