Skip to content

Commit c1321f5

Browse files
authored
chore: use static allocation to get status (#83)
1 parent c79a12b commit c1321f5

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/http/ngx_http_wasm_api.c

+4-13
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ static char *str_buf[STR_BUF_SIZE] = {0};
8888

8989
static ngx_str_t scheme_https = ngx_string("https");
9090
static ngx_str_t scheme_http = ngx_string("http");
91-
static ngx_str_t status_ok = ngx_string("200");
91+
static unsigned char status_data_buf[NGX_INT_T_LEN];
92+
static ngx_str_t status_str = { 0, status_data_buf };
9293

9394
static ngx_http_wasm_h2_header_t wasm_h2_req_header_static_table[] = {
9495
{ngx_string(":path"), PROXY_WASM_REQUEST_HEADER_PATH, ngx_http_wasm_get_path},
@@ -650,27 +651,17 @@ static ngx_str_t *ngx_http_wasm_get_scheme(ngx_http_request_t *r)
650651
static ngx_str_t *
651652
ngx_http_wasm_get_status(ngx_http_request_t *r)
652653
{
653-
ngx_str_t *sc;
654654
ngx_uint_t status;
655-
u_char *p;
656655

657656
if (r->err_status) {
658657
status = r->err_status;
659658
} else {
660659
status = r->headers_out.status;
661660
}
662661

663-
sc = &status_ok;
662+
status_str.len = ngx_sprintf(status_str.data, "%ui", status) - status_str.data;
664663

665-
p = ngx_http_wasm_get_string_buf(r->pool, sizeof(u_char));
666-
if (p == NULL) {
667-
return NULL;
668-
}
669-
670-
sc->len = ngx_sprintf(p, "%ui", status) - p;
671-
sc->data = p;
672-
673-
return sc;
664+
return &status_str;
674665
}
675666

676667

0 commit comments

Comments
 (0)