Skip to content

Instantly share code, notes, and snippets.

@angeloped
Created December 19, 2021 15:27
Show Gist options
  • Save angeloped/43a8add2bf466eb3968f99df0b2b96fa to your computer and use it in GitHub Desktop.
Save angeloped/43a8add2bf466eb3968f99df0b2b96fa to your computer and use it in GitHub Desktop.
Strip HTTP header in C language.
const char* pattern = "\r\n\r\n";
const char* patp = pattern;
while ((numbytes = recv(socket_file_descriptor, buf, MAXDATASIZE - 1, 0)) > 0) {
for (int i = 0; i < numbytes; i++) {
if (*patp == 0) {
fwrite(buf + i, 1, numbytes - i, fp);
break;
}
else if (buf[i] == *patp) ++patp;
else patp = pattern;
}
/* This memset isn't really necessary */
memset(buf, 0, MAXDATASIZE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment