Skip to content

Commit 2af8373

Browse files
committed
update pre-content phase handler to be able handle with length
1 parent 33b4748 commit 2af8373

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ngx_feature_incs="#include <ngx_http_c_func_module.h>"
2424
ngx_feature_path=
2525
ngx_feature_libs=
2626
# ngx_feature_exit_if_not_found=yes
27-
ngx_feature_test="int ngx_http_c_func_module_current_version_=ngx_http_c_func_module_version_11;"
27+
ngx_feature_test="int ngx_http_c_func_module_current_version_=ngx_http_c_func_module_version_12;"
2828
. auto/feature
2929

3030
if [ $ngx_found != yes ]; then

src/ngx_http_c_func_module.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static ngx_int_t ngx_http_c_func_proceed_init_calls(ngx_cycle_t* cycle, ngx_htt
131131
static u_char* ngx_http_c_func_strdup_with_p(ngx_pool_t *pool, const char *src, size_t len);
132132

133133
static ngx_int_t ngx_http_c_func_get_resp_var(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
134-
static void ngx_http_c_func_set_resp_var_with_r(ngx_http_request_t *r, ngx_http_c_func_ctx_t *ctx, const char* resp_content);
134+
static void ngx_http_c_func_set_resp_var_with_r(ngx_http_request_t *r, ngx_http_c_func_ctx_t *ctx, const char* resp_content, size_t resp_len);
135135
static void ngx_http_c_func_output_filter(ngx_http_request_t *r);
136136

137137
#if (NGX_THREADS)
@@ -182,7 +182,7 @@ void* ngx_http_c_func_cache_get(void *shared_mem, const char* key);
182182
void* ngx_http_c_func_cache_put(void *shared_mem, const char* key, void* value);
183183
void* ngx_http_c_func_cache_new(void *shared_mem, const char* key, size_t size);
184184
void* ngx_http_c_func_cache_remove(void *shared_mem, const char* key);
185-
void ngx_http_c_func_set_resp_var(ngx_http_c_func_ctx_t *ctx, const char* resp_content);
185+
void ngx_http_c_func_set_resp_var(ngx_http_c_func_ctx_t *ctx, const char* resp_content, size_t resp_len);
186186
void ngx_http_c_func_write_resp(ngx_http_c_func_ctx_t *ctx, uintptr_t status_code, const char* status_line, const char* content_type, const char* resp_content, size_t resp_len);
187187
void ngx_http_c_func_write_resp_l(ngx_http_c_func_ctx_t *ctx, uintptr_t status_code, const char* status_line,
188188
size_t status_line_len, const char* content_type, size_t content_type_len,
@@ -559,7 +559,7 @@ ngx_http_c_func_pre_configuration(ngx_conf_t *cf) {
559559
return NGX_ERROR;
560560
#endif
561561

562-
#ifndef ngx_http_c_func_module_version_11
562+
#ifndef ngx_http_c_func_module_version_12
563563
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "the latest ngx_http_c_func_module.h not found in the c header path, \
564564
please copy latest ngx_http_c_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
565565
with read and write permission.");
@@ -1486,15 +1486,16 @@ ngx_http_c_func_get_resp_var(ngx_http_request_t *r,
14861486
void
14871487
ngx_http_c_func_set_resp_var(
14881488
ngx_http_c_func_ctx_t *ctx,
1489-
const char* resp_content
1489+
const char* resp_content,
1490+
size_t resp_len
14901491
) {
14911492
ngx_http_c_func_internal_ctx_t *internal_ctx;
14921493
ngx_http_request_t *r = (ngx_http_request_t*)ctx->__r__;
14931494
internal_ctx = ngx_http_get_module_ctx(r, ngx_http_c_func_module);
14941495

14951496
if (internal_ctx != NULL) {
1496-
internal_ctx->resp_len = ngx_strlen(resp_content);
1497-
internal_ctx->resp = ngx_http_c_func_strdup_with_p(r->pool, resp_content, internal_ctx->resp_len);
1497+
internal_ctx->resp_len = resp_len;
1498+
internal_ctx->resp = ngx_http_c_func_strdup_with_p(r->pool, resp_content, resp_len);
14981499

14991500
/** Decline means continue to next handler for this phase **/
15001501
internal_ctx->rc = NGX_DECLINED;
@@ -1508,14 +1509,15 @@ static void
15081509
ngx_http_c_func_set_resp_var_with_r(
15091510
ngx_http_request_t *r,
15101511
ngx_http_c_func_ctx_t *ctx,
1511-
const char* resp_content
1512+
const char* resp_content,
1513+
size_t resp_len
15121514
) {
15131515
ngx_http_c_func_internal_ctx_t *internal_ctx;
15141516
internal_ctx = ngx_http_get_module_ctx(r, ngx_http_c_func_module);
15151517

15161518
if (internal_ctx != NULL) {
1517-
internal_ctx->resp_len = ngx_strlen(resp_content);
1518-
internal_ctx->resp = ngx_http_c_func_strdup_with_p(r->pool, resp_content, internal_ctx->resp_len);
1519+
internal_ctx->resp_len = resp_len;
1520+
internal_ctx->resp = ngx_http_c_func_strdup_with_p(r->pool, resp_content, resp_len);
15191521

15201522
/** Decline means continue to next handler for this phase **/
15211523
internal_ctx->rc = NGX_DECLINED;
@@ -1545,9 +1547,8 @@ ngx_http_c_func_write_resp_l(
15451547
if ( ((ngx_http_c_func_loc_conf_t*) ngx_http_get_module_loc_conf(r, ngx_http_c_func_module) )->_is_call_to_var ) {
15461548
ngx_log_error(NGX_LOG_WARN,
15471549
r->connection->log,
1548-
0, "Recommended to call ngx_http_c_func_set_resp_var. \
1549-
ngx_http_c_func_write_resp only applicable when no variable specified");
1550-
ngx_http_c_func_set_resp_var_with_r(r, appctx, resp_content);
1550+
0, "Recommended to call ngx_http_c_func_set_resp_var. ngx_http_c_func_write_resp only applicable when no variable specified");
1551+
ngx_http_c_func_set_resp_var_with_r(r, appctx, resp_content, resp_content_len);
15511552
return;
15521553
}
15531554

src/ngx_http_c_func_module.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <stdlib.h>
4141
#include <stdint.h>
4242

43-
#define ngx_http_c_func_module_version_11 11
43+
#define ngx_http_c_func_module_version_12 12
4444

4545

4646
#define ngx_http_c_func_content_type_plaintext "text/plain"
@@ -104,7 +104,8 @@ extern void ngx_http_c_func_write_resp_l(
104104

105105
extern void ngx_http_c_func_set_resp_var(
106106
ngx_http_c_func_ctx_t *ctx,
107-
const char* resp_content
107+
const char* resp_content,
108+
size_t resp_len
108109
);
109110

110111
// Shared Memory and Cache Scope

0 commit comments

Comments
 (0)