I am trying to write an http server. Right now I am working on reading an http request using the following function:
int read_http_request(int socket, char *buf, int len)
{
char *s = buf;
int chars_read = 0;
int c;
int count = 0;
do {
s += chars_read;
c = recv(socket, s, len - chars_read, 0);
chars_read += c;
} while ((c > 0) && (strstr(s, "\r\n\n") == NULL) && (chars_read <= len));
if (c < 0) return c;
return chars_read;
}
The data in the buffer looks something like this:
GET / HTTP/1.1
Host: 127.0.0.1
Connection: keep
which is missing the "-alive" portion. When using postman, it reads the request line and just one header.