79403566

Date: 2025-01-31 17:40:13
Score: 1
Natty:
Report link

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.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @AndreasWenze
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Mehan Alavi