]> git.kaiwu.me - njs.git/commitdiff
Tests: added request body test when body is in a file.
authorDmitry Volyntsev <xeioex@nginx.com>
Sat, 18 Jan 2025 01:03:08 +0000 (17:03 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 23 Jan 2025 00:05:47 +0000 (16:05 -0800)
nginx/t/js_request_body.t

index 350e7fb8303b16c784dc83642b1487c076ac9386..7a5005d4ca179ecd49f9af7a4bb48a7c0be6cb64 100644 (file)
@@ -51,12 +51,19 @@ http {
             client_body_in_file_only on;
             js_content test.body;
         }
+
+        location /read_body_from_temp_file {
+            client_body_in_file_only clean;
+            js_content test.read_body_from_temp_file;
+        }
     }
 }
 
 EOF
 
 $t->write_file('test.js', <<EOF);
+    import fs from 'fs';
+
     function body(r) {
         try {
             var body = r.requestText;
@@ -67,11 +74,16 @@ $t->write_file('test.js', <<EOF);
         }
     }
 
-    export default {body};
+    function read_body_from_temp_file(r) {
+        let fn = r.variables.request_body_file;
+        r.return(200, fs.readFileSync(fn));
+    }
+
+    export default {body, read_body_from_temp_file};
 
 EOF
 
-$t->try_run('no njs request body')->plan(3);
+$t->try_run('no njs request body')->plan(4);
 
 ###############################################################################
 
@@ -80,6 +92,8 @@ like(http_post('/in_file'), qr/request body is in a file/,
        'request body in file');
 like(http_post_big('/body'), qr/200.*^(1234567890){1024}$/ms,
                'request body big');
+like(http_post_big('/read_body_from_temp_file'),
+       qr/200.*^(1234567890){1024}$/ms, 'request body big from temp file');
 
 ###############################################################################