Welcome! Log In Create A New Profile

Advanced

[nginx] Perl: avoid returning 500 if header was already sent.

Maxim Dounin
July 12, 2019 10:56AM
details: https://hg.nginx.org/nginx/rev/fd9252844ec1
branches:
changeset: 7530:fd9252844ec1
user: Maxim Dounin <mdounin@mdounin.ru>
date: Fri Jul 12 15:39:25 2019 +0300
description:
Perl: avoid returning 500 if header was already sent.

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.

diffstat:

src/http/modules/perl/nginx.xs | 2 ++
src/http/modules/perl/ngx_http_perl_module.c | 4 ++++
src/http/modules/perl/ngx_http_perl_module.h | 1 +
3 files changed, 7 insertions(+), 0 deletions(-)

diffs (37 lines):

diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -164,6 +164,8 @@ send_http_header(r, ...)
}
}

+ ctx->header_sent = 1;
+
r->disable_not_modified = 1;

rc = ngx_http_send_header(r);
diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -780,6 +780,10 @@ ngx_http_perl_call_handler(pTHX_ ngx_htt

ctx->redirect_uri.len = 0;

+ if (ctx->header_sent) {
+ return NGX_ERROR;
+ }
+
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

diff --git a/src/http/modules/perl/ngx_http_perl_module.h b/src/http/modules/perl/ngx_http_perl_module.h
--- a/src/http/modules/perl/ngx_http_perl_module.h
+++ b/src/http/modules/perl/ngx_http_perl_module.h
@@ -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 */

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Perl: avoid returning 500 if header was already sent.

Maxim Dounin 228 July 12, 2019 10:56AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 151
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready