]> git.kaiwu.me - njs.git/commitdiff
Fetch: introduced ngx_js_chain_to_buf() helper function.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 15 Oct 2025 00:42:07 +0000 (17:42 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 27 Oct 2025 16:03:09 +0000 (09:03 -0700)
nginx/ngx_js_http.c
nginx/ngx_js_http.h

index 9389bbca93d6f5ab86fbed22fad37759faa9e762..400d42d239929803fc7b051db3eeaa7b9bb3c550 100644 (file)
@@ -521,21 +521,12 @@ ngx_js_http_write_handler(ngx_event_t *wev)
     b = http->buffer;
 
     if (b == NULL) {
-        size = njs_chb_size(&http->chain);
-        if (size < 0) {
-            ngx_js_http_error(http, "memory error");
-            return;
-        }
-
-        b = ngx_create_temp_buf(http->pool, size);
+        b = ngx_js_chain_to_buf(http->pool, &http->chain);
         if (b == NULL) {
             ngx_js_http_error(http, "memory error");
             return;
         }
 
-        njs_chb_join_to(&http->chain, b->last);
-        b->last += size;
-
         http->buffer = b;
     }
 
@@ -1861,6 +1852,29 @@ close:
 }
 
 
+ngx_buf_t *
+ngx_js_chain_to_buf(ngx_pool_t *pool, njs_chb_t *chain)
+{
+    ssize_t     size;
+    ngx_buf_t  *buf;
+
+    size = njs_chb_size(chain);
+    if (size < 0) {
+        return NULL;
+    }
+
+    buf = ngx_create_temp_buf(pool, size);
+    if (buf == NULL) {
+        return NULL;
+    }
+
+    njs_chb_join_to(chain, buf->last);
+    buf->last += size;
+
+    return buf;
+}
+
+
 static void
 ngx_js_fetch_append_request_headers(njs_chb_t *chain,
     ngx_js_request_t *request)
index 51f0bcd439df20595be60d70fa7ed73b9d8c0b0f..bb6496852a9365176b5c25b4abc01200878d7ac4 100644 (file)
@@ -167,6 +167,8 @@ void ngx_js_http_trim(u_char **value, size_t *len,
     int trim_c0_control_or_space);
 ngx_int_t ngx_js_check_header_name(u_char *name, size_t len);
 
+ngx_buf_t *ngx_js_chain_to_buf(ngx_pool_t *pool, njs_chb_t *chain);
+
 void ngx_js_fetch_build_request(ngx_js_http_t *http, ngx_js_request_t *request,
     ngx_str_t *path, ngx_url_t *u);