From 54db6049b774c18500ebf702a42e090e8ab98be0 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sat, 23 May 2020 18:58:19 +0400 Subject: [PATCH] Byte-range parsing not exposed in the header file --- src/server/request_context.cpp | 56 ++++++++++++++++++---------------- src/server/request_context.h | 3 -- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/server/request_context.cpp b/src/server/request_context.cpp index 0e73345a3..1d467669e 100644 --- a/src/server/request_context.cpp +++ b/src/server/request_context.cpp @@ -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 RequestContext::RequestContext(struct MHD_Connection* connection, @@ -93,33 +122,6 @@ RequestContext::RequestContext(struct MHD_Connection* connection, 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, const char *key, const char *value) { diff --git a/src/server/request_context.h b/src/server/request_context.h index ea30d1bbe..13744b7fb 100644 --- a/src/server/request_context.h +++ b/src/server/request_context.h @@ -86,9 +86,6 @@ class RequestContext { bool can_compress() const { return acceptEncodingDeflate; } - private: // functions - static ByteRange parse_byte_range(std::string range); - private: // data std::string full_url; std::string url;