@@ -1114,7 +1114,7 @@ ngx_http_c_func_log_err(ngx_http_c_func_ctx_t *ctx, const char* msg) {
1114
1114
char *
1115
1115
ngx_http_c_func_strdup (ngx_http_c_func_ctx_t * ctx , const char * src ) {
1116
1116
char * dst ;
1117
- if (src == NULL ) return NULL ;
1117
+ if (src == NULL ) return NULL ;
1118
1118
size_t len = ngx_strlen (src );
1119
1119
dst = (char * ) ngx_palloc ((ngx_pool_t * )ctx -> __pl__ , (len + 1 ) * sizeof (char ));
1120
1120
ngx_memcpy (dst , src , len );
@@ -1367,7 +1367,7 @@ ngx_http_c_func_set_resp_var(
1367
1367
1368
1368
if (internal_ctx != NULL ) {
1369
1369
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 ) ;
1371
1371
1372
1372
/** Decline means continue to next handler for this phase **/
1373
1373
ctx -> __rc__ = NGX_DECLINED ;
@@ -1388,7 +1388,7 @@ ngx_http_c_func_set_resp_var_with_r(
1388
1388
1389
1389
if (internal_ctx != NULL ) {
1390
1390
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 ) ;
1392
1392
1393
1393
/** Decline means continue to next handler for this phase **/
1394
1394
ctx -> __rc__ = NGX_DECLINED ;
@@ -1431,18 +1431,17 @@ ngx_http_c_func_write_resp(
1431
1431
}
1432
1432
1433
1433
ngx_buf_t * b ;
1434
- /* Allocate a new buffer for sending out the reply. */
1435
- b = ngx_pcalloc (r -> pool , sizeof (ngx_buf_t ));
1436
1434
1437
1435
if ( resp_content ) {
1438
1436
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 );
1441
1440
} 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 ;
1446
1445
}
1447
1446
1448
1447
b -> memory = 1 ; /* content is in read-only memory */
0 commit comments