I created a C ++ application using WinSck, which has a small one (it processes only a few functions that I need), the http server was implemented. This is used to communicate with the outside world using HTTP requests. It works, but sometimes requests are not processed correctly because parsing is not performed. Now I am sure that the requests are correctly formed, as they are sent by large web browsers such as firefox / chrome or perl / C # (which have http modules / dll).
After some debugging, I found out that the problem is getting the message. When a message arrives no more than one part (it cannot be read in one call recv()), sometimes parsing is not performed. I have made many attempts to solve this problem, but nothing seems reliable enough.
What I'm doing right now is that I read the data until I find a sequence "\r\n\r\n"that indicates the end of the header. If WSAGetLastError()it reports something else than 10035 (connection closed / failed) before such a sequence is found, I will discard this message. When I know that I have the whole title, I parse it and looked for information about the length of the body. However, I am not sure that this information is mandatory (I think not), and what should I do if there is no such information - then there will be no body? Another problem is that I do not know if I should search "\r\n\r\n"after the body (if its length is greater than zero).
Does anyone know how to parse an http message reliably?
Note. I know that there are implementations of http servers. I want my own for various reasons. And yes, reinventing the wheel is bad, I know that too.
source
share