17 #ifndef COM_BORA_SOFTWARE__BALAU_RESOURCE__HTTP 18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__HTTP 35 public:
Http() =
default;
40 public:
explicit Http(std::string && uri_) :
Url(
std::move(uri_)) {}
45 public:
explicit Http(std::string_view uri_) :
Url(uri_) {}
50 public:
explicit Http(
const char * uri_) :
Url(uri_) {}
55 public:
Http(
const Http & copy) =
default;
62 public: std::unique_ptr<Uri>
clone()
const override {
63 return std::unique_ptr<Uri>(
new Http(*
this));
66 public: std::unique_ptr<Uri>
append(
const std::string & pathComponent)
const override {
67 return std::unique_ptr<Uri>(
new Http(appendPathComponent(pathComponent)));
70 public: std::unique_ptr<Uri>
resolve(std::string_view path)
const override {
71 static const std::regex scheme {
"[a-zA-Z][a-zA-Z0-9+-\\.]*:" };
74 auto str = std::string(cleanPath);
77 std::unique_ptr<Uri> uri;
87 return std::unique_ptr<Uri>(
new Http(url));
92 return std::unique_ptr<Uri>(
new Http(url));
97 const auto * o =
dynamic_cast<const Http *
>(&rhs);
98 return o !=
nullptr && uri == o->uri;
110 return ::toString<AllocatorT>(uri);
155 public: std::unique_ptr<UriIterator>
iterator()
const override {
169 template <
typename AllocatorT>
176 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__HTTP virtual void dispatch(const File &object)=0
Visit a File URI.
HttpByteReadResource getByteReadResource() const
Get a byte read resource for the HTTP source.
Definition: Http.hpp:116
Http()=default
Create a null HTTP URI.
std::unique_ptr< Uri > append(const std::string &pathComponent) const override
Appends the path component to the supplied URI, returning a new URI.
Definition: Http.hpp:66
std::unique_ptr< Uri > clone() const override
Clone the concrete Uri.
Definition: Http.hpp:62
A read-only HTTP UTF-8 resource which is read as UTF-32 characters.
Definition: HttpUtf8To32ReadResource.hpp:35
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
void fromString(File &destination, std::string_view value)
Overwrite the supplied file URI by assignment by converting the supplied UTF-8 string to a file URI...
Definition: File.hpp:733
A read-only HTTP resource which is read as bytes.
Definition: HttpByteReadResource.hpp:33
An abstract universal resource identifier.
Definition: Uri.hpp:131
Http(std::string &&uri_)
Create an HTTP URI from the supplied URI string.
Definition: Http.hpp:40
std::unique_ptr< Utf8To32ReadResource > utf8To32ReadResource() const override
Get a UTF-8 to UTF-32 read resource for the URI.
Definition: Http.hpp:131
std::unique_ptr< UriIterator > iterator() const override
Get a (non-recursive) iterator.
Definition: Http.hpp:155
bool operator==(const Uri &rhs) const override
Compare the supplied URI to the current URI.
Definition: Http.hpp:96
The unified resource class hierarchy.
Definition: ByteReadResource.hpp:24
An HTTP URL.
Definition: Http.hpp:31
Thrown when a feature is not yet implemented.
Definition: BalauException.hpp:162
bool isRecursivelyIterable() const override
Does the URI have a recursive iterator (examples: file and zip archive URIs).
Definition: Http.hpp:143
std::string_view host() const
Obtain a string view to the host.
Definition: UriComponents.hpp:205
std::unique_ptr< ByteWriteResource > byteWriteResource() override
Get a byte write resource for the URI.
Definition: Http.hpp:135
Http(std::string_view uri_)
Create an HTTP URI from the supplied URI string.
Definition: Http.hpp:45
std::unique_ptr< ByteReadResource > byteReadResource() const override
Get a byte read resource for the URI.
Definition: Http.hpp:127
Balau::U8String< AllocatorT > toString(const File &file)
Print the file URI as a UTF-8 string.
Definition: File.hpp:724
std::unique_ptr< Uri > resolve(std::string_view path) const override
Resolve the relative or absolute path, in reference to the current URI.
Definition: Http.hpp:70
An abstract Url (either http or https).
static bool startsWith(const StringT< CharT, T ... > &str, const PrefixT &prefix)
Does the string start with the specified prefix?
Definition: Strings.hpp:46
static std::string_view trim(const std::string_view &input)
Trim whitespace from the beginning and end of the supplied UTF-8 string.
Definition: Strings.hpp:706
A read-only HTTP UTF-8 resource which is read as UTF-32 characters.
bool isIterable() const override
Does the URI have a non-recursive iterator (examples: file and zip archive URIs). ...
Definition: Http.hpp:147
Http(const char *uri_)
Create an HTTP URI from the supplied URI string.
Definition: Http.hpp:50
Http(Http &&rhs) noexcept
Create an HTTP URI by moving the contents of the supplied instance.
Definition: Http.hpp:60
A read-only HTTP resource which is read as bytes.
Base Balau exception classes.
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
void dispatch(UriDispatcher &dispatcher) const override
Visitor pattern dispatching.
Definition: Http.hpp:159
std::string_view scheme() const
Obtain a string view to the scheme.
Definition: UriComponents.hpp:177
std::string_view path() const
Obtain a string view to the path.
Definition: UriComponents.hpp:234
static bool startsWithRegex(const std::string &str, const std::regex &prefix)
Does the string start with the specified regular expression?
Definition: Strings.hpp:94
HttpUtf8To32ReadResource getUtf8To32ReadResource() const
Get a UTF-8 to UTF-32 read resource for the HTTP source.
Definition: Http.hpp:123
std::unique_ptr< Utf32To8WriteResource > utf32To8WriteResource() override
Get a UTF-32 to UTF-8 write resource for the URI.
Definition: Http.hpp:139
bool canWriteTo() const override
Can data be written to the URI via a write resource.
Definition: Http.hpp:105
A class representing the parsed components of a URI.
std::unique_ptr< RecursiveUriIterator > recursiveIterator() const override
Get a recursive iterator.
Definition: Http.hpp:151
bool canReadFrom() const override
Can data be read from the URI via a read resource.
Definition: Http.hpp:101
An abstract Url (either http or https).
Definition: Url.hpp:28
Visitor interface for URIs.
Definition: UriDispatcher.hpp:32
Parses a URI and provides views into the URI's components.
Definition: UriComponents.hpp:52
Balau::U8String< AllocatorT > toRawString() const
Get a string representing the raw URI.
Definition: Http.hpp:109