From 0c5bb3fcfe3863a9838b9bbb926e8a72bace10be Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sat, 23 May 2020 20:08:53 +0400 Subject: [PATCH] Moved ByteRange to a header file of its own --- src/server/byte_range.h | 42 ++++++++++++++++++++++++++++++++++ src/server/request_context.cpp | 4 +--- src/server/request_context.h | 16 ++----------- src/server/response.cpp | 2 +- 4 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 src/server/byte_range.h diff --git a/src/server/byte_range.h b/src/server/byte_range.h new file mode 100644 index 000000000..4579133d3 --- /dev/null +++ b/src/server/byte_range.h @@ -0,0 +1,42 @@ +/* + * Copyright 2020 Veloman Yunkan + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#ifndef KIWIXLIB_SERVER_BYTE_RANGE_H +#define KIWIXLIB_SERVER_BYTE_RANGE_H + +namespace kiwix { + +class ByteRange +{ + public: // functions + ByteRange() : ByteRange(0, -1) {} + ByteRange(int64_t first, int64_t last) : first_(first), last_(last) {} + + int64_t first() const { return first_; } + int64_t last() const { return last_; } + + private: // data + int64_t first_; + int64_t last_; +}; + +} // namespace kiwix + +#endif //KIWIXLIB_SERVER_BYTE_RANGE_H diff --git a/src/server/request_context.cpp b/src/server/request_context.cpp index fb54ca9ef..963f75c34 100644 --- a/src/server/request_context.cpp +++ b/src/server/request_context.cpp @@ -62,8 +62,6 @@ 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}; @@ -202,7 +200,7 @@ bool RequestContext::has_range() const { return byteRange_.first() <= byteRange_.last(); } -RequestContext::ByteRange RequestContext::get_range() const { +ByteRange RequestContext::get_range() const { return byteRange_; } diff --git a/src/server/request_context.h b/src/server/request_context.h index 100e2fa35..3256e30e5 100644 --- a/src/server/request_context.h +++ b/src/server/request_context.h @@ -27,6 +27,8 @@ #include #include +#include "byte_range.h" + extern "C" { #include } @@ -51,20 +53,6 @@ class IndexError: public std::runtime_error {}; class RequestContext { - public: // types - class ByteRange { - public: // functions - ByteRange() : ByteRange(0, -1) {} - ByteRange(int64_t first, int64_t last) : first_(first), last_(last) {} - - int64_t first() const { return first_; } - int64_t last() const { return last_; } - - private: // data - int64_t first_; - int64_t last_; - }; - public: // functions RequestContext(struct MHD_Connection* connection, std::string rootLocation, diff --git a/src/server/response.cpp b/src/server/response.cpp index 448753dc9..23da5c12c 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -39,7 +39,7 @@ bool is_compressible_mime_type(const std::string& mimeType) || mimeType.find("application/json") != string::npos; } -int get_range_len(const kiwix::Entry& entry, RequestContext::ByteRange range) +int get_range_len(const kiwix::Entry& entry, ByteRange range) { const int64_t entrySize = entry.getSize(); return range.last() == -1