Skip to content

Commit 4b39060

Browse files
committed
code tuning
1 parent b6524e4 commit 4b39060

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

src/ngx_http_c_func_module.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static ngx_int_t ngx_http_c_func_proceed_init_calls(ngx_cycle_t* cycle, ngx_htt
122122
static u_char* ngx_http_c_func_strdup(ngx_pool_t *pool, const char *src, size_t len);
123123

124124
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);
125+
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);
125126

126127
/*** Download Feature Support ***/
127128
typedef struct {
@@ -144,7 +145,7 @@ static ngx_http_c_fun_http_header_body* ngx_http_c_fun_https_request( ngx_cycle_
144145
#endif
145146
/*** End Download Feature Support ***/
146147

147-
/*Extern interface*/
148+
/**Extern interface**/
148149
void ngx_http_c_func_log_debug(ngx_http_c_func_ctx_t *ctx, const char* msg);
149150
void ngx_http_c_func_log_info(ngx_http_c_func_ctx_t *ctx, const char* msg);
150151
void ngx_http_c_func_log_warn(ngx_http_c_func_ctx_t *ctx, const char* msg);
@@ -165,20 +166,10 @@ void* ngx_http_c_func_cache_get(void *shared_mem, const char* key);
165166
void* ngx_http_c_func_cache_put(void *shared_mem, const char* key, void* value);
166167
void* ngx_http_c_func_cache_new(void *shared_mem, const char* key, size_t size);
167168
void* ngx_http_c_func_cache_remove(void *shared_mem, const char* key);
169+
void ngx_http_c_func_set_resp_var(ngx_http_c_func_ctx_t *ctx, const char* resp_content);
170+
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);
171+
/**End Extern interface**/
168172

169-
void
170-
ngx_http_c_func_set_resp_var(
171-
ngx_http_c_func_ctx_t *ctx,
172-
const char* resp_content
173-
);
174-
175-
void ngx_http_c_func_write_resp(
176-
ngx_http_c_func_ctx_t *ctx,
177-
uintptr_t status_code,
178-
const char* status_line,
179-
const char* content_type,
180-
const char* resp_content
181-
);
182173

183174
// static ngx_conf_post_t ngx_http_c_func_srv_post_conf = {
184175
// ngx_http_c_func_srv_post_conf_handler
@@ -1368,6 +1359,27 @@ ngx_http_c_func_set_resp_var(
13681359
}
13691360
}
13701361

1362+
static void
1363+
ngx_http_c_func_set_resp_var_with_r(
1364+
ngx_http_request_t *r,
1365+
ngx_http_c_func_ctx_t *ctx,
1366+
const char* resp_content
1367+
) {
1368+
ngx_http_c_func_internal_ctx_t *internal_ctx;
1369+
internal_ctx = ngx_http_get_module_ctx(r, ngx_http_c_func_module);
1370+
1371+
if (internal_ctx != NULL) {
1372+
internal_ctx->resp_len = ngx_strlen(resp_content);
1373+
internal_ctx->resp = (u_char*)resp_content;
1374+
1375+
/** Decline means continue to next handler for this phase **/
1376+
ctx->__rc__ = NGX_DECLINED;
1377+
} else {
1378+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Error while storing resp to variable.");
1379+
ctx->__rc__ = NGX_HTTP_INTERNAL_SERVER_ERROR;
1380+
}
1381+
}
1382+
13711383
void
13721384
ngx_http_c_func_write_resp(
13731385
ngx_http_c_func_ctx_t *ctx,
@@ -1384,9 +1396,10 @@ ngx_http_c_func_write_resp(
13841396
if ( ((ngx_http_c_func_loc_conf_t*) ngx_http_get_module_loc_conf(r, ngx_http_c_func_module) )->_is_call_to_var ) {
13851397
ngx_log_error(NGX_LOG_WARN,
13861398
r->connection->log,
1387-
0,
1388-
", \n Recommended to call ngx_http_c_func_set_resp_var. \n ngx_http_c_func_write_resp only applicable when no variable stored");
1389-
return ngx_http_c_func_set_resp_var(ctx, resp_content);
1399+
0, "Recommended to call ngx_http_c_func_set_resp_var. \
1400+
ngx_http_c_func_write_resp only applicable when no variable specified");
1401+
ngx_http_c_func_set_resp_var_with_r(r, ctx, resp_content);
1402+
return;
13901403
}
13911404

13921405
/* Set the Content-Type header. */

0 commit comments

Comments
 (0)