[all] Replace HTTPContextBase/HTTPRequestBase with FileSource
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
#include <mbgl/storage/http_context_base.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef MBGL_STORAGE_HTTP_CONTEXT_BASE
|
||||
#define MBGL_STORAGE_HTTP_CONTEXT_BASE
|
||||
|
||||
#include <mbgl/storage/http_request_base.hpp>
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class HTTPContextBase {
|
||||
public:
|
||||
static std::unique_ptr<HTTPContextBase> createContext();
|
||||
static uint32_t maximumConcurrentRequests();
|
||||
|
||||
virtual ~HTTPContextBase() = default;
|
||||
virtual HTTPRequestBase* createRequest(const Resource&, HTTPRequestBase::Callback) = 0;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif // MBGL_STORAGE_HTTP_CONTEXT_BASE
|
||||
25
src/mbgl/storage/http_file_source.hpp
Normal file
25
src/mbgl/storage/http_file_source.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef MBGL_STORAGE_HTTP_FILE_SOURCE
|
||||
#define MBGL_STORAGE_HTTP_FILE_SOURCE
|
||||
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class HTTPFileSource : public FileSource {
|
||||
public:
|
||||
HTTPFileSource();
|
||||
~HTTPFileSource() override;
|
||||
|
||||
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
|
||||
|
||||
static uint32_t maximumConcurrentRequests();
|
||||
|
||||
private:
|
||||
friend class HTTPRequest;
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif // MBGL_STORAGE_HTTP_FILE_SOURCE
|
||||
@@ -1,23 +0,0 @@
|
||||
#include <mbgl/storage/http_request_base.hpp>
|
||||
|
||||
#include <mbgl/util/http_header.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
optional<SystemTimePoint> HTTPRequestBase::parseCacheControl(const char *value) {
|
||||
if (!value) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto cacheControl = http::CacheControl::parse(value);
|
||||
if (!cacheControl.maxAge) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Round trip through time_t to truncate fractional seconds.
|
||||
return SystemClock::from_time_t(SystemClock::to_time_t(
|
||||
SystemClock::now() + std::chrono::seconds(*cacheControl.maxAge)));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef MBGL_STORAGE_HTTP_REQUEST_BASE
|
||||
#define MBGL_STORAGE_HTTP_REQUEST_BASE
|
||||
|
||||
#include <mbgl/storage/response.hpp>
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class Response;
|
||||
|
||||
class HTTPRequestBase : private util::noncopyable {
|
||||
public:
|
||||
using Callback = std::function<void (Response)>;
|
||||
|
||||
HTTPRequestBase(const Resource& resource_, Callback notify_)
|
||||
: resource(resource_)
|
||||
, notify(std::move(notify_))
|
||||
, cancelled(false) {
|
||||
}
|
||||
|
||||
virtual ~HTTPRequestBase() = default;
|
||||
virtual void cancel() { cancelled = true; };
|
||||
|
||||
protected:
|
||||
static optional<SystemTimePoint> parseCacheControl(const char *value);
|
||||
|
||||
Resource resource;
|
||||
Callback notify;
|
||||
bool cancelled;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif // MBGL_STORAGE_HTTP_REQUEST_BASE
|
||||
@@ -25,5 +25,13 @@ CacheControl CacheControl::parse(const std::string& value) {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<SystemTimePoint> CacheControl::toTimePoint() const {
|
||||
// Round trip through time_t to truncate fractional seconds.
|
||||
return maxAge
|
||||
? SystemClock::from_time_t(SystemClock::to_time_t(
|
||||
SystemClock::now() + std::chrono::seconds(*maxAge)))
|
||||
: optional<SystemTimePoint>();
|
||||
}
|
||||
|
||||
} // namespace http
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_UTIL_HTTP_HEADER
|
||||
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -14,6 +15,8 @@ public:
|
||||
|
||||
optional<uint64_t> maxAge;
|
||||
bool mustRevalidate = false;
|
||||
|
||||
optional<SystemTimePoint> toTimePoint() const;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
|
||||
Reference in New Issue
Block a user