Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating HTTP Response Body from Header in C++

I'm currently writing my own C++ HTTP class for a certain project. And I'm trying to find a way to separate the response body from the header, because that's the only part I need to return.

Here's a sample of the raw http headers if you're not familiar with it:

HTTP/1.1 200 OK
Server: nginx/0.7.65
Date: Wed, 29 Dec 2010 06:13:07 GMT
Content-Type: text
Connection: keep-alive
Vary: Cookie
Content-Length: 82

Below that is the HTML/Response body. What would be the best way to do this? I'm only using Winsock library for the requests by the way (I don't even think this matters).

Thanks in advance.

like image 525
Ruel Avatar asked Nov 28 '22 15:11

Ruel


1 Answers

HTTP headers are terminated by the sequence \r\n\r\n (a blank line). Just search for that, and return everything after. (It may not exist of course, e.g. if it was in response to a HEAD request.)

like image 89
j_random_hacker Avatar answered Dec 03 '22 11:12

j_random_hacker