Skip to content

Commit 789e36b

Browse files
committed
feature: added the new configuration directive "lua_use_default_type" for controlling whether to send out a default Content-Type response header (as defined by the "default_type" directive). default on. thanks aviramc for the patch in #286.
1 parent d8a2664 commit 789e36b

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

src/ngx_http_lua_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ typedef struct {
201201
ngx_flag_t transform_underscores_in_resp_headers;
202202
ngx_flag_t log_socket_errors;
203203
ngx_flag_t check_client_abort;
204+
ngx_flag_t use_default_type;
204205
} ngx_http_lua_loc_conf_t;
205206

206207

src/ngx_http_lua_headers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ ngx_http_lua_ngx_header_set(lua_State *L)
497497
}
498498

499499
if (!ctx->headers_set) {
500-
rc = ngx_http_set_content_type(r);
500+
rc = ngx_http_lua_set_content_type(r);
501501
if (rc != NGX_OK) {
502502
return luaL_error(L,
503503
"failed to set default content type: %d",

src/ngx_http_lua_module.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ static ngx_command_t ngx_http_lua_cmds[] = {
343343
offsetof(ngx_http_lua_loc_conf_t, check_client_abort),
344344
NULL },
345345

346+
{ ngx_string("lua_use_default_type"),
347+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
348+
|NGX_CONF_FLAG,
349+
ngx_conf_set_flag_slot,
350+
NGX_HTTP_LOC_CONF_OFFSET,
351+
offsetof(ngx_http_lua_loc_conf_t, use_default_type),
352+
NULL },
353+
346354
ngx_null_command
347355
};
348356

@@ -616,6 +624,7 @@ ngx_http_lua_create_loc_conf(ngx_conf_t *cf)
616624
conf->enable_code_cache = NGX_CONF_UNSET;
617625
conf->http10_buffering = NGX_CONF_UNSET;
618626
conf->check_client_abort = NGX_CONF_UNSET;
627+
conf->use_default_type = NGX_CONF_UNSET;
619628

620629
conf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
621630
conf->connect_timeout = NGX_CONF_UNSET_MSEC;
@@ -679,6 +688,7 @@ ngx_http_lua_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
679688
ngx_conf_merge_value(conf->enable_code_cache, prev->enable_code_cache, 1);
680689
ngx_conf_merge_value(conf->http10_buffering, prev->http10_buffering, 1);
681690
ngx_conf_merge_value(conf->check_client_abort, prev->check_client_abort, 0);
691+
ngx_conf_merge_value(conf->use_default_type, prev->use_default_type, 1);
682692

683693
ngx_conf_merge_msec_value(conf->keepalive_timeout,
684694
prev->keepalive_timeout, 60000);

src/ngx_http_lua_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ ngx_http_lua_send_header_if_needed(ngx_http_request_t *r,
484484
r->headers_out.status = NGX_HTTP_OK;
485485
}
486486

487-
if (!ctx->headers_set && ngx_http_set_content_type(r) != NGX_OK) {
487+
if (!ctx->headers_set && ngx_http_lua_set_content_type(r) != NGX_OK) {
488488
return NGX_ERROR;
489489
}
490490

src/ngx_http_lua_util.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ ngx_http_lua_hash_str(u_char *src, size_t n)
249249
}
250250

251251

252+
static ngx_inline ngx_int_t
253+
ngx_http_lua_set_content_type(ngx_http_request_t *r)
254+
{
255+
ngx_http_lua_loc_conf_t *llcf;
256+
257+
llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
258+
if (llcf->use_default_type) {
259+
return ngx_http_set_content_type(r);
260+
}
261+
262+
return NGX_OK;
263+
}
264+
265+
252266
extern ngx_uint_t ngx_http_lua_location_hash;
253267
extern ngx_uint_t ngx_http_lua_content_length_hash;
254268

0 commit comments

Comments
 (0)