comparison src/http/modules/perl/nginx.xs @ 7531:ede052c67512

Perl: additional ctx->header_sent checks. As we now have ctx->header_sent flag, it is further used to prevent duplicate $r->send_http_header() calls, prevent output before sending header, and $r->internal_redirect() after sending header. Further, $r->send_http_header() protected from calls after $r->internal_redirect().
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 12 Jul 2019 15:39:25 +0300
parents fd9252844ec1
children 975d7ab37b39
comparison
equal deleted inserted replaced
7530:fd9252844ec1 7531:ede052c67512
137 croak("send_http_header(): called after error"); 137 croak("send_http_header(): called after error");
138 } 138 }
139 139
140 if (ctx->variable) { 140 if (ctx->variable) {
141 croak("send_http_header(): cannot be used in variable handler"); 141 croak("send_http_header(): cannot be used in variable handler");
142 }
143
144 if (ctx->header_sent) {
145 croak("send_http_header(): header already sent");
146 }
147
148 if (ctx->redirect_uri.len) {
149 croak("send_http_header(): cannot be used with internal_redirect()");
142 } 150 }
143 151
144 if (r->headers_out.status == 0) { 152 if (r->headers_out.status == 0) {
145 r->headers_out.status = NGX_HTTP_OK; 153 r->headers_out.status = NGX_HTTP_OK;
146 } 154 }
664 672
665 if (ctx->variable) { 673 if (ctx->variable) {
666 croak("print(): cannot be used in variable handler"); 674 croak("print(): cannot be used in variable handler");
667 } 675 }
668 676
677 if (!ctx->header_sent) {
678 croak("print(): header not sent");
679 }
680
669 if (items == 2) { 681 if (items == 2) {
670 682
671 /* 683 /*
672 * do zero copy for prolate single read-only SV: 684 * do zero copy for prolate single read-only SV:
673 * $r->print("some text\n"); 685 * $r->print("some text\n");
778 790
779 if (ctx->variable) { 791 if (ctx->variable) {
780 croak("sendfile(): cannot be used in variable handler"); 792 croak("sendfile(): cannot be used in variable handler");
781 } 793 }
782 794
795 if (!ctx->header_sent) {
796 croak("sendfile(): header not sent");
797 }
798
783 filename = SvPV_nolen(ST(1)); 799 filename = SvPV_nolen(ST(1));
784 800
785 if (filename == NULL) { 801 if (filename == NULL) {
786 croak("sendfile(): NULL filename"); 802 croak("sendfile(): NULL filename");
787 } 803 }
884 900
885 if (ctx->variable) { 901 if (ctx->variable) {
886 croak("flush(): cannot be used in variable handler"); 902 croak("flush(): cannot be used in variable handler");
887 } 903 }
888 904
905 if (!ctx->header_sent) {
906 croak("flush(): header not sent");
907 }
908
889 b = ngx_calloc_buf(r->pool); 909 b = ngx_calloc_buf(r->pool);
890 if (b == NULL) { 910 if (b == NULL) {
891 ctx->error = 1; 911 ctx->error = 1;
892 croak("ngx_calloc_buf() failed"); 912 croak("ngx_calloc_buf() failed");
893 } 913 }
917 937
918 ngx_http_perl_set_request(r, ctx); 938 ngx_http_perl_set_request(r, ctx);
919 939
920 if (ctx->variable) { 940 if (ctx->variable) {
921 croak("internal_redirect(): cannot be used in variable handler"); 941 croak("internal_redirect(): cannot be used in variable handler");
942 }
943
944 if (ctx->header_sent) {
945 croak("internal_redirect(): header already sent");
922 } 946 }
923 947
924 uri = ST(1); 948 uri = ST(1);
925 949
926 if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) { 950 if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) {