]> git.kaiwu.me - nginx.git/commitdiff
Perl: avoid returning 500 if header was already sent.
authorMaxim Dounin <mdounin@mdounin.ru>
Fri, 12 Jul 2019 12:39:25 +0000 (15:39 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Fri, 12 Jul 2019 12:39:25 +0000 (15:39 +0300)
Returning NGX_HTTP_INTERNAL_SERVER_ERROR if a perl code died after
sending header will lead to a "header already sent" alert.  To avoid
it, we now check if header was already sent, and return NGX_ERROR
instead if it was.

src/http/modules/perl/nginx.xs
src/http/modules/perl/ngx_http_perl_module.c
src/http/modules/perl/ngx_http_perl_module.h

index 67ec0a56427ff271422ebac2cbae2ba9f3265582..34ce9daeda04e30235bc2a814d428c34cb5d2cc5 100644 (file)
@@ -164,6 +164,8 @@ send_http_header(r, ...)
         }
     }
 
+    ctx->header_sent = 1;
+
     r->disable_not_modified = 1;
 
     rc = ngx_http_send_header(r);
index 81b2526add575e84a8be4680afd1e4ea2a5c519a..dc2125935fb37af28c78602e4c4bbec8bd324835 100644 (file)
@@ -780,6 +780,10 @@ ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r,
 
         ctx->redirect_uri.len = 0;
 
+        if (ctx->header_sent) {
+            return NGX_ERROR;
+        }
+
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
index b67ce137cc5bd7047ac5cb30bd8ade5a786d50ef..da3a162353eaac25711e5e6141444389c0878799 100644 (file)
@@ -34,6 +34,7 @@ typedef struct {
     unsigned                  done:1;
     unsigned                  error:1;
     unsigned                  variable:1;
+    unsigned                  header_sent:1;
 
     ngx_array_t              *variables;  /* array of ngx_http_perl_var_t */