Skip to content

Commit ad9e89e

Browse files
committed
bug fixed to internal handling buffering response.
1 parent 4839b17 commit ad9e89e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/ngx_http_c_func_module.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ ngx_http_c_func_log_err(ngx_http_c_func_ctx_t *ctx, const char* msg) {
11141114
char*
11151115
ngx_http_c_func_strdup(ngx_http_c_func_ctx_t *ctx, const char *src) {
11161116
char *dst;
1117-
if (src == NULL) return NULL;
1117+
if (src == NULL) return NULL;
11181118
size_t len = ngx_strlen(src);
11191119
dst = (char*) ngx_palloc((ngx_pool_t*)ctx->__pl__, (len + 1) * sizeof(char));
11201120
ngx_memcpy(dst, src, len);
@@ -1367,7 +1367,7 @@ ngx_http_c_func_set_resp_var(
13671367

13681368
if (internal_ctx != NULL) {
13691369
internal_ctx->resp_len = ngx_strlen(resp_content);
1370-
internal_ctx->resp = (u_char*)resp_content;
1370+
internal_ctx->resp = ngx_http_c_func_strdup_with_p(r->pool, resp_content, internal_ctx->resp_len);
13711371

13721372
/** Decline means continue to next handler for this phase **/
13731373
ctx->__rc__ = NGX_DECLINED;
@@ -1388,7 +1388,7 @@ ngx_http_c_func_set_resp_var_with_r(
13881388

13891389
if (internal_ctx != NULL) {
13901390
internal_ctx->resp_len = ngx_strlen(resp_content);
1391-
internal_ctx->resp = (u_char*)resp_content;
1391+
internal_ctx->resp = ngx_http_c_func_strdup_with_p(r->pool, resp_content, internal_ctx->resp_len);
13921392

13931393
/** Decline means continue to next handler for this phase **/
13941394
ctx->__rc__ = NGX_DECLINED;
@@ -1431,18 +1431,17 @@ ngx_http_c_func_write_resp(
14311431
}
14321432

14331433
ngx_buf_t *b;
1434-
/* Allocate a new buffer for sending out the reply. */
1435-
b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
14361434

14371435
if ( resp_content ) {
14381436
resp_content_len = ngx_strlen(resp_content);
1439-
b->pos = (u_char*)resp_content; /* first position in memory of the data */
1440-
b->last = (u_char*) (resp_content + resp_content_len); /* last position in memory of the data */
1437+
/* Allocate a new buffer for sending out the reply. */
1438+
b = ngx_create_temp_buf(r->pool, resp_content_len);
1439+
b->last = ngx_copy(b->last, resp_content, resp_content_len);
14411440
} else {
1442-
static const char* emptyLine = "\n";
1443-
resp_content_len = ngx_strlen(emptyLine);
1444-
b->pos = (u_char*)emptyLine; /* first position in memory of the data */
1445-
b->last = (u_char*) (emptyLine + resp_content_len); /* last position in memory of the data */
1441+
/* Allocate a new buffer for sending out the reply. */
1442+
resp_content_len = 1;
1443+
b = ngx_create_temp_buf(r->pool, resp_content_len);
1444+
*b->last++ = LF;
14461445
}
14471446

14481447
b->memory = 1; /* content is in read-only memory */

0 commit comments

Comments
 (0)