Ushering out strlcpy()
Ushering out strlcpy()
Posted Aug 26, 2022 6:43 UTC (Fri) by wtarreau (subscriber, #51152)In reply to: Ushering out strlcpy() by NYKevin
Parent article: Ushering out strlcpy()
With all these design constraints explained, it seems quite complicated to efficiently fold HTTP headers in a request, which simply consists in replacing the optional CR and the LF preceeding a space or tab, with a space or tab (i.e. overwrite two bytes in a buffer at known positions). In C that could be as simple as:
void fold(char *hdr)
{
char *lf;
for (lf = hdr; (lf = strchr(lf, '\n')); lf++) {
if (*(lf + 1) != ' ' && *(lf + 1) != '\t')
continue;
if (lf > hdr && *(lf - 1) == '\r')
*(lf - 1) = ' ';
*lf = ' ';
}
}
Here your description makes it sounds like you'd have to deal with complicated blocks of known lengths which would be error-prone, or even worse, dynamic allocation which is a total no-go in protocol parsers. Or maybe there's a way to still keep the simple solutions such as above (possibly in unsafe mode) ?
