fix parser HttpRequestHeader (#12757)

* fix parser HttpRequestHeader
This commit is contained in:
mmyduckx
2022-09-14 15:29:33 +08:00
committed by GitHub
parent 44dd12a6fe
commit 9f64efb024
3 changed files with 32 additions and 35 deletions

View File

@@ -124,12 +124,20 @@ public:
/* append custom headers one by one */
for (auto &header : headers) {
uint32_t len = header.length();
uint32_t pos = header.find(':');
if (-1 == pos || pos >= len) {
ccstd::string::size_type pos = header.find(':');
if (ccstd::string::npos == pos || pos >= len) {
continue;
}
ccstd::string str1 = header.substr(0, pos);
ccstd::string str2 = header.substr(pos + 1, len - pos - 1);
ccstd::string str2 = header.substr(pos + 1);
// trim \n at the end of the string
if (!str2.empty() && str2[str2.size() - 1] == '\n') {
str2.erase(str2.size() - 1);
}
// trim leading space (header is field: value format)
if (!str2.empty() && str2[0] == ' ') {
str2.erase(0, 1);
}
addRequestHeader(str1.c_str(), str2.c_str());
}
}