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.
47 lines
922 B
C++
47 lines
922 B
C++
![]()
7 years ago
|
#include "webcc/http_response_parser.h"
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
#include "webcc/logger.h"
|
||
![]()
7 years ago
|
#include "webcc/http_response.h"
|
||
![]()
8 years ago
|
|
||
![]()
7 years ago
|
namespace webcc {
|
||
![]()
8 years ago
|
|
||
|
HttpResponseParser::HttpResponseParser(HttpResponse* response)
|
||
![]()
7 years ago
|
: HttpParser(response), response_(response) {
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
bool HttpResponseParser::ParseStartLine(const std::string& line) {
|
||
![]()
7 years ago
|
std::size_t off = 0;
|
||
![]()
8 years ago
|
|
||
![]()
7 years ago
|
std::size_t pos = line.find(' ');
|
||
![]()
8 years ago
|
if (pos == std::string::npos) {
|
||
![]()
7 years ago
|
return false;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
|
// HTTP version
|
||
|
|
||
|
off = pos + 1; // Skip space.
|
||
|
|
||
|
pos = line.find(' ', off);
|
||
|
if (pos == std::string::npos) {
|
||
![]()
7 years ago
|
return false;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
|
// Status code
|
||
|
std::string status_str = line.substr(off, pos - off);
|
||
|
|
||
|
try {
|
||
![]()
7 years ago
|
response_->set_status(std::stoi(status_str));
|
||
|
} catch (const std::exception&) {
|
||
![]()
7 years ago
|
LOG_ERRO("Invalid HTTP status: %s", status_str.c_str());
|
||
|
return false;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
if (response_->status() != HttpStatus::kOK) {
|
||
![]()
7 years ago
|
return false;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
return true;
|
||
![]()
8 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
} // namespace webcc
|