You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
906 B
C++
41 lines
906 B
C++
![]()
6 years ago
|
#include "webcc/response_parser.h"
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
#include "boost/algorithm/string.hpp"
|
||
|
|
||
![]()
6 years ago
|
#include "webcc/response.h"
|
||
![]()
6 years ago
|
#include "webcc/logger.h"
|
||
![]()
8 years ago
|
|
||
![]()
7 years ago
|
namespace webcc {
|
||
![]()
8 years ago
|
|
||
![]()
6 years ago
|
ResponseParser::ResponseParser(Response* response)
|
||
|
: Parser(response), response_(response) {
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
6 years ago
|
void ResponseParser::Init(Response* response) {
|
||
|
Parser::Init(response);
|
||
![]()
6 years ago
|
response_ = response;
|
||
|
}
|
||
|
|
||
![]()
6 years ago
|
bool ResponseParser::ParseStartLine(const std::string& line) {
|
||
![]()
6 years ago
|
std::vector<std::string> parts;
|
||
|
boost::split(parts, line, boost::is_any_of(" "), boost::token_compress_on);
|
||
![]()
8 years ago
|
|
||
![]()
6 years ago
|
if (parts.size() < 3) {
|
||
![]()
7 years ago
|
LOG_ERRO("Invalid HTTP response status line: %s", line.c_str());
|
||
![]()
7 years ago
|
return false;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
6 years ago
|
std::string& status_str = parts[1];
|
||
![]()
8 years ago
|
|
||
|
try {
|
||
![]()
7 years ago
|
response_->set_status(std::stoi(status_str));
|
||
|
} catch (const std::exception&) {
|
||
![]()
7 years ago
|
LOG_ERRO("Invalid HTTP status code: %s", status_str.c_str());
|
||
![]()
7 years ago
|
return false;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
return true;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
} // namespace webcc
|