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.
WebCC/src/csoap/http_response_parser.cc

50 lines
1018 B
C++

#include "csoap/http_response_parser.h"
#include "boost/lexical_cast.hpp"
#include "csoap/http_response.h"
namespace csoap {
HttpResponseParser::HttpResponseParser(HttpResponse* response)
: HttpParser(response)
, response_(response) {
}
Error HttpResponseParser::ParseStartLine(const std::string& line) {
response_->set_start_line(line + "\r\n");
size_t off = 0;
size_t pos = line.find(' ');
if (pos == std::string::npos) {
return kHttpStartLineError;
}
// HTTP version
off = pos + 1; // Skip space.
pos = line.find(' ', off);
if (pos == std::string::npos) {
return kHttpStartLineError;
}
// Status code
std::string status_str = line.substr(off, pos - off);
try {
response_->set_status(boost::lexical_cast<int>(status_str));
} catch (boost::bad_lexical_cast&) {
return kHttpStartLineError;
}
off = pos + 1; // Skip space.
if (response_->status() != HttpStatus::kOK) {
return kHttpStatusError;
}
return kNoError;
}
} // namespace csoap