Separate body from request

hello guys i'm creating simple personal web server i've using TcpListener and TcpStream;
so please tell me how to seperate the json body from request? without using any external crates?

POST /json HTTP/1.1
Host: 127.0.0.1:8000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0
Accept: /
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json
Content-Length: 15
Connection: keep-alive

{"name":"blah"} <- json body

If you want to parse protocol, always start from the spec. As you can see in section 4.1, each header fields are separated by CRLF(\r\n) token, and the header itself is separated with the body by another CRLF, an empty line.

Each header is terminated by an \r\n, and the body is separated from the headers with \r\n\r\n, so once you see those four bytes, your body starts.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.