refactor: network - harden TCP/IP and unify HTTP clients
This commit is contained in:
@@ -140,26 +140,6 @@ unsigned decode_utf8_codepoint(const char* buf, int len, int* consumed) {
|
||||
return '?';
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// HTTP parsing
|
||||
// ============================================================================
|
||||
|
||||
int find_header_end(const char* buf, int len) {
|
||||
for (int i = 0; i + 3 < len; i++)
|
||||
if (buf[i]=='\r' && buf[i+1]=='\n' && buf[i+2]=='\r' && buf[i+3]=='\n')
|
||||
return i + 4;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int parse_status_code(const char* buf, int len) {
|
||||
int i = 0;
|
||||
while (i < len && buf[i] != ' ') i++;
|
||||
if (i >= len || i + 3 >= len) return -1;
|
||||
i++;
|
||||
if (buf[i] < '0' || buf[i] > '9') return -1;
|
||||
return (buf[i]-'0')*100 + (buf[i+1]-'0')*10 + (buf[i+2]-'0');
|
||||
}
|
||||
|
||||
int find_substr(const char* buf, int len, const char* needle) {
|
||||
int nlen = (int)strlen(needle);
|
||||
if (!buf || !needle || nlen <= 0 || nlen > len) return -1;
|
||||
|
||||
Reference in New Issue
Block a user