mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-09-02 15:02:51 +08:00
A POST /cmd whose body arrives in a separate TCP segment from the headers executed nothing: handle_post() read the body from the segment that carried the request line, found it empty, and answered 200 OK. Python's urllib and requests both write headers and body separately, so every scripted command from those clients became a silent no-op. POST /login had the same hole. The multipart endpoints were fixed earlier; this covers the plain ones. When the first segment holds fewer body bytes than Content-Length announces, the bytes accumulate in config_buf (idle outside multipart uploads) and the connection waits in TSTATE_POSTBODY; once the announced length is in, the endpoint runs against the buffer. The /cmd and /login executions move into run_cmd_body() and run_login_body() so both paths share them; the 200 OK builder they duplicated becomes send_ok(), and run_login_body() checks the pwd= prefix instead of skipping four bytes blindly. The announced length is the contract on both paths. A body that arrives with the headers is terminated at Content-Length before it runs, so pipelined bytes after it are not executed as commands the way the old code did. A request without a usable Content-Length answers 411: without one there is no way to know when the body has arrived, and the old 200 OK for an empty body is the bug this fixes. Bodies announced at or above the buffer size answer 400 before anything is buffered. The wait state has a deadline. uIP is built with a single connection, and an ESTABLISHED connection with nothing in flight never times out on its own, so headers followed by silence (a script interrupted, a link dropped mid-request, or someone holding the socket on purpose) would otherwise keep the slot until reboot; POST /login reaches the wait before authentication. The poll handler aborts the connection when the body has made no progress for five seconds, measured on the 200 Hz system tick rather than on poll count, which runs faster under interrupt load.