Hydra 0.0.1
A convenience networking library for modern C++
 
Loading...
Searching...
No Matches
http_stream.h
1#ifndef SOURCEMETA_HYDRA_HTTP_STREAM_H
2#define SOURCEMETA_HYDRA_HTTP_STREAM_H
3
4#ifndef SOURCEMETA_HYDRA_HTTP_EXPORT
5#include <sourcemeta/hydra/http_export.h>
6#endif
7
8#include <cstdint> // std::uint8_t
9#include <functional> // std::function
10#include <memory> // std::unique_ptr
11#include <span> // std::span
12#include <string> // std::string
13#include <string_view> // std::string_view
14#include <vector> // std::vector
15
16namespace sourcemeta::hydra::http {
17
20class SOURCEMETA_HYDRA_HTTP_EXPORT ClientStream {
21public:
52 ClientStream(std::string url);
53
63 ClientStream(ClientStream &&other) noexcept;
64
74 auto operator=(ClientStream &&other) noexcept -> ClientStream &;
75
76 // While technically possible, copy semantics are not very useful here
77 // Also, not worth documenting these.
78#if !defined(DOXYGEN)
79 ClientStream(const ClientStream &other) = delete;
80 auto operator=(const ClientStream &other) -> ClientStream & = delete;
81#endif
82
85
110 auto method(const Method method) noexcept -> void;
111
123 auto method() const noexcept -> Method;
124
146 auto header(std::string_view key, std::string_view value) -> void;
147
169 auto header(std::string_view key, int value) -> void;
170
180 auto url() const -> std::string_view;
181
214 auto send() -> Status;
215
216 using DataCallback =
217 std::function<void(const Status, std::span<const std::uint8_t>)>;
218 using HeaderCallback =
219 std::function<void(const Status, std::string_view, std::string_view)>;
220 using BodyCallback =
221 std::function<std::vector<std::uint8_t>(const std::size_t)>;
222
246 auto on_data(DataCallback callback) noexcept -> void;
247
270 auto on_header(HeaderCallback callback) noexcept -> void;
271
302 auto on_body(BodyCallback callback) noexcept -> void;
303
304private:
305 struct Internal;
306
307 // No need to make this private, as the contents of `Internal`
308 // are already hidden with the PIMPL idiom.
309public:
310// Exporting symbols that depends on the standard C++ library is considered
311// safe.
312// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
313#if defined(_MSC_VER)
314#pragma warning(disable : 4251)
315#endif
316 std::unique_ptr<Internal> internal;
317#if defined(_MSC_VER)
318#pragma warning(default : 4251)
319#endif
320};
321
322} // namespace sourcemeta::hydra::http
323
324#endif
Definition http_stream.h:20
auto method() const noexcept -> Method
auto method(const Method method) noexcept -> void
auto operator=(ClientStream &&other) noexcept -> ClientStream &
~ClientStream()
Destruct an instance of this class.
ClientStream(ClientStream &&other) noexcept
Status
Definition http_status.h:10
Method
Definition http_method.h:8