Moved ByteRange to a header file of its own

This commit is contained in:
Veloman Yunkan 2020-05-23 20:08:53 +04:00
parent 3fba8c20a0
commit 0c5bb3fcfe
4 changed files with 46 additions and 18 deletions

42
src/server/byte_range.h Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright 2020 Veloman Yunkan <veloman.yunkan@gmail.com>
*
* 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

View File

@ -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 parse_byte_range(std::string range)
{ {
ByteRange byteRange{0, -1}; ByteRange byteRange{0, -1};
@ -202,7 +200,7 @@ bool RequestContext::has_range() const {
return byteRange_.first() <= byteRange_.last(); return byteRange_.first() <= byteRange_.last();
} }
RequestContext::ByteRange RequestContext::get_range() const { ByteRange RequestContext::get_range() const {
return byteRange_; return byteRange_;
} }

View File

@ -27,6 +27,8 @@
#include <map> #include <map>
#include <stdexcept> #include <stdexcept>
#include "byte_range.h"
extern "C" { extern "C" {
#include <microhttpd.h> #include <microhttpd.h>
} }
@ -51,20 +53,6 @@ class IndexError: public std::runtime_error {};
class RequestContext { 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 public: // functions
RequestContext(struct MHD_Connection* connection, RequestContext(struct MHD_Connection* connection,
std::string rootLocation, std::string rootLocation,

View File

@ -39,7 +39,7 @@ bool is_compressible_mime_type(const std::string& mimeType)
|| mimeType.find("application/json") != string::npos; || 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(); const int64_t entrySize = entry.getSize();
return range.last() == -1 return range.last() == -1