Byte-range parsing not exposed in the header file

This commit is contained in:
Veloman Yunkan 2020-05-23 18:58:19 +04:00
parent 81c38d6b2b
commit 54db6049b7
2 changed files with 29 additions and 30 deletions

View File

@ -62,6 +62,35 @@ fullURL2LocalURL(const std::string& full_url, const std::string& rootLocation)
} }
} }
using ByteRange = RequestContext::ByteRange;
ByteRange parse_byte_range(std::string range)
{
ByteRange byteRange{0, -1};
const std::string byteUnitSpec("bytes=");
if ( kiwix::startsWith(range, byteUnitSpec) ) {
range.erase(0, byteUnitSpec.size());
int start = 0;
int end = -1;
std::istringstream iss(range);
char c;
iss >> start >> c;
if (iss.good() && c=='-') {
iss >> end;
if (iss.fail()) {
// Something went wrong while extracting
end = -1;
}
if (iss.eof()) {
byteRange = ByteRange(start, end);
}
}
}
return byteRange;
}
} // unnamed namespace } // unnamed namespace
RequestContext::RequestContext(struct MHD_Connection* connection, RequestContext::RequestContext(struct MHD_Connection* connection,
@ -93,33 +122,6 @@ RequestContext::RequestContext(struct MHD_Connection* connection,
RequestContext::~RequestContext() RequestContext::~RequestContext()
{} {}
RequestContext::ByteRange RequestContext::parse_byte_range(std::string range)
{
ByteRange byteRange{0, -1};
const std::string byteUnitSpec("bytes=");
if ( kiwix::startsWith(range, byteUnitSpec) ) {
range.erase(0, byteUnitSpec.size());
int start = 0;
int end = -1;
std::istringstream iss(range);
char c;
iss >> start >> c;
if (iss.good() && c=='-') {
iss >> end;
if (iss.fail()) {
// Something went wrong while extracting
end = -1;
}
if (iss.eof()) {
byteRange = ByteRange(start, end);
}
}
}
return byteRange;
}
int RequestContext::fill_header(void *__this, enum MHD_ValueKind kind, int RequestContext::fill_header(void *__this, enum MHD_ValueKind kind,
const char *key, const char *value) const char *key, const char *value)
{ {

View File

@ -86,9 +86,6 @@ class RequestContext {
bool can_compress() const { return acceptEncodingDeflate; } bool can_compress() const { return acceptEncodingDeflate; }
private: // functions
static ByteRange parse_byte_range(std::string range);
private: // data private: // data
std::string full_url; std::string full_url;
std::string url; std::string url;