mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-21 19:34:20 +08:00
Bug fix & New function
This commit is contained in:
@@ -527,7 +527,7 @@ bool Response::pullData() {
|
||||
void Response::parseStatus() {
|
||||
if (this->code) return;
|
||||
auto line = this->readLine();
|
||||
auto parts = str_util::str_splitv(line, " ", 3);
|
||||
auto parts = str_util::str_splitv(line, " ");
|
||||
if (parts.size() < 3) {
|
||||
throw std::runtime_error("Invalid HTTP status line");
|
||||
}
|
||||
@@ -537,7 +537,7 @@ void Response::parseStatus() {
|
||||
if (sscanf(parts[1].c_str(), "%" SCNu16, &this->code) != 1) {
|
||||
throw std::runtime_error("Invalid HTTP status code");
|
||||
}
|
||||
this->reason = parts[2];
|
||||
this->reason = str_util::str_join(std::list(parts.begin() + 2, parts.end()), " ");
|
||||
}
|
||||
|
||||
void Response::parseHeader(Request& req) {
|
||||
|
||||
10
str_util.cpp
10
str_util.cpp
@@ -109,3 +109,13 @@ std::string str_util::str_trim(std::string input) {
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
std::string str_util::str_join(std::list<std::string> input, std::string pattern) {
|
||||
std::string output;
|
||||
for (auto i = input.begin(); i != input.end();) {
|
||||
output += *i;
|
||||
i++;
|
||||
if (i != input.end()) output += pattern;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -70,5 +70,12 @@ namespace str_util {
|
||||
* @return Result
|
||||
*/
|
||||
std::string remove_quote(std::string input);
|
||||
/**
|
||||
* @brief Join a list of string with a pattern
|
||||
* @param input Input list
|
||||
* @param pattern Pattern
|
||||
* @return Result
|
||||
*/
|
||||
std::string str_join(std::list<std::string> input, std::string pattern);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user