File tree Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -3149,7 +3149,15 @@ ngx_http_lua_req_socket(lua_State *L)
3149
3149
lua_pushliteral (L , "nginx version too old" );
3150
3150
return 2 ;
3151
3151
#else
3152
- if (!r -> request_body ) {
3152
+ if (r -> request_body ) {
3153
+ if (r -> request_body -> rest > 0 ) {
3154
+ lua_pushnil (L );
3155
+ lua_pushliteral (L , "pending request body reading in some "
3156
+ "other thread" );
3157
+ return 2 ;
3158
+ }
3159
+
3160
+ } else {
3153
3161
rb = ngx_pcalloc (r -> pool , sizeof (ngx_http_request_body_t ));
3154
3162
if (rb == NULL ) {
3155
3163
return luaL_error (L , "out of memory" );
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use t::TestNginxLua;
5
5
6
6
repeat_each(2);
7
7
8
- plan tests => repeat_each() * 33 ;
8
+ plan tests => repeat_each() * 36 ;
9
9
10
10
our $HtmlDir = html_dir;
11
11
@@ -735,3 +735,47 @@ hello
735
735
--- no_error_log
736
736
[error]
737
737
738
+
739
+
740
+ === TEST 14: pending request body reading
741
+ --- config
742
+ server_tokens off;
743
+ location = /t {
744
+ content_by_lua '
745
+ ngx.thread.spawn(function ()
746
+ ngx.req.read_body()
747
+ end)
748
+
749
+ local sock, err = ngx.req.socket(true)
750
+ if not sock then
751
+ ngx.log(ngx.WARN, "server: failed to get raw req socket: ", err)
752
+ return ngx.exit(444)
753
+ end
754
+
755
+ local data, err = sock:receive(5)
756
+ if not data then
757
+ ngx.log(ngx.ERR, "failed to receive: ", err)
758
+ return
759
+ end
760
+
761
+ local ok, err = sock:send("HTTP/1.1 200 OK\\r\\nContent-Length: 5\\r\\n\\r\\n" .. data)
762
+ if not ok then
763
+ ngx.log(ngx.ERR, "failed to send: ", err)
764
+ return
765
+ end
766
+ ';
767
+ }
768
+
769
+ --- raw_request eval
770
+ "GET /t HTTP/1.0\r
771
+ Host: localhost\r
772
+ Content-Length: 5\r
773
+ \r
774
+ hell"
775
+ --- ignore_response
776
+ --- no_error_log
777
+ [error]
778
+ [alert]
779
+ --- error_log
780
+ server: failed to get raw req socket: pending request body reading in some other thread
781
+
You can’t perform that action at this time.
0 commit comments