As @AndreasWenze Pointed out The HTTP newline is actually \r\n
not \n
.
Updated code:
void receiveHTTP(int clientSockfd, char *buff, size_t __n, int __flags)
{
int bytes = recv(clientSockfd, buff, __n, __flags);
printf("%s",buff);
for (int i = 0; i < bytes; i++)
{
if (buff[i+1] != '\n' && buff[i] != '\n' ){
printf("%c", buff[i]);
}
}
printf("\n");
}
Output:
GET /1 HTTP/1.1
user-agent: got (https://github.com/sindresorhus/got)
accept-encoding: gzip, deflate, br
cookie: PHPSESSID=37f65v1f9dcbmq3nbvqvev6bf4
Host: localhost:8080
Connection: close
GET /1 HTTP/1.1user-agent: got (https://github.com/sindresorhus/got)accept-encoding: gzip, deflate, brcookie: PHPSESSID=37f65v1f9dcbmq3nbvqvev6bf4Host: localhost:8080Connection: close
Which is correct.