Optimize http parser.

This commit is contained in:
Xie Han
2025-09-23 22:04:51 +08:00
parent 92febf72b0
commit c81a156f0f

View File

@@ -275,20 +275,31 @@ static int __parse_start_line(const char *ptr, size_t len,
if (ptr[i + 1] != '\n')
return -2;
start_line[i] = '\0';
len = i;
while (len > 0 && start_line[len - 1] == ' ')
len--;
start_line[len] = '\0';
p1 = start_line;
while (*p1 == ' ')
p1++;
p2 = strchr(p1, ' ');
if (p2)
*p2++ = '\0';
else
if (!p2)
return -2;
*p2++ = '\0';
while (*p2 == ' ')
p2++;
p3 = strchr(p2, ' ');
if (p3)
*p3++ = '\0';
else
if (!p3)
return -2;
*p3++ = '\0';
while (*p3 == ' ')
p3++;
if (parser->is_resp)
ret = __match_status_line(p1, p2, p3, parser);
else
@@ -302,7 +313,7 @@ static int __parse_start_line(const char *ptr, size_t len,
return 1;
}
if (start_line[i] == 0)
if (start_line[i] == '\0')
return -2;
}