processing a request without body
Maxim Dounin
mdounin at mdounin.ru
Sat Jan 13 13:38:01 UTC 2024
Hello!
On Sat, Jan 13, 2024 at 03:11:11PM +0800, Muhammad Nuzaihan wrote:
> Hi Maxim,
>
> I did enable debug logs before i posted the question.
>
> With json payload, my code is executed right after doing malloc and
> "http request body content length filter".
>
> Without a json payload, it doesn't execute my request
> validation.That's why i thought it might be due to content length is
> 0.
>
> Here is the debug log when i curl with an empty payload:
>
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 rewrite phase: 0
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 test location: "/"
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 test location: "proxy/health"
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 test location: "proxy/unhealthy"
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 test location:
> "proxy/profile/alice/comment"
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 using configuration
> "/proxy/profile/alice/comment"
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 http cl:0 max:1048576
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 rewrite phase: 2
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 post rewrite phase: 3
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 generic phase: 4
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 http request body content
> length filter
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 http read client request body
Clearly request body reading is called here, at the preaccess
phase. This implies that your code is called - nginx itself won't
try to read the request body that early. Everything else is up to
your code.
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 recv: eof:0, avail:0
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 http client request body recv -2
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 http client request body rest 1
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 event timer add: 3: 60000:183385517
Note that request body reading code blocks waiting for more data.
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 http finalize request: -4,
> "/proxy/profile/alice/comment?" a:1, c:2
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 http request count:2 blk:0
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 access phase: 7
> 2024/01/13 15:01:19 [debug] 2452969#0: *11 access phase: 8
Note that phase handling continues here: it shouldn't, since
request body reading is in progress.
This suggested that your code fails to stop phase handling after
calling ngx_http_read_client_request_body(): note you should
return NGX_DONE to stop processing unless there is an immediate
error.
[...]
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx-devel
mailing list