]> git.kaiwu.me - njs.git/commitdiff
HTTP: fixed handling of 0 length request body.
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 20 May 2024 23:44:10 +0000 (16:44 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Mon, 20 May 2024 23:44:10 +0000 (16:44 -0700)
Previously, when r.requestBuffer was passed as a body argument to
ngx.fetch() or r.subrequest() then exception was thrown "Error: invalid
Request body" when the request body had 0 length.

src/njs_vm.c

index 7a2b0632ff248e91c34dc16403f54a6106ddc1e5..7183a24c7287c1961eff5e790a182002a73491be 100644 (file)
@@ -1602,6 +1602,12 @@ njs_vm_value_to_bytes(njs_vm_t *vm, njs_str_t *dst, njs_value_t *src)
         }
 
         if (njs_slow_path(njs_is_detached_buffer(buffer))) {
+            if (length == 0) {
+                dst->length = 0;
+                dst->start = NULL;
+                return NJS_OK;
+            }
+
             njs_type_error(vm, "detached buffer");
             return NJS_ERROR;
         }