// TJP COPYRIGHT HEADER #pragma once #include "Internet.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Data.hpp" #include "Headers.hpp" #include namespace tjp::core::internet { constexpr size_t GeneralFailure = 0xFFFF; using Header = Tuple; using Headers = Vector
; using StatusCode = s64; using HeadersCallback = Function; using ProgressiveCallback = Function; using CompleteCallback = Function; struct HttpOptions { Headers headers; time_t lastModifiedTime = 0; time_t timeout = 0; bool throwOnFailure = true; size_t maxRedirects = 0; Optional httpVersion; Optional verbose; HeadersCallback onHeaders; ProgressiveCallback onData; CompleteCallback onComplete; } ; namespace HttpStatusCodes { const size_t NotModified = 304; const size_t OK = 200; } ; inline HttpOptions makeEmptyOptions() { return {}; } struct FileContents { Headers headers; DataBlock data; StatusCode statusCode = GeneralFailure; time_t lastModifiedTime = 0; bool ok() const { return statusCode < 400; } } ; struct Exception : core::Exception { using Super = core::Exception; Optional contents; Exception ( const String &what_, Optional &&contents_ ) : Super(what_), contents(std::move(contents_)) { } const Optional &getContents() const { return contents; } } ; Future get(const std::string &url, const HttpOptions &o = makeEmptyOptions()); Future post(const std::string &url, Data &&, const HttpOptions &o = makeEmptyOptions()); Future put(const std::string &url, Data &&, const HttpOptions &o = makeEmptyOptions()); } // namespace #ifdef TJP_CORE_HEADER_ONLY #if defined(SYS_IOS) #include "ios/Internet.hpp" #else #include "curl/Internet.hpp" #endif #endif