Files
spark/src/lib/io/URL.h
T
John Colvin f9db93e41a Add simple HTTPClient
The binance depth stream must be bootstrapped with a depth snapshot,
which is retrieved via an HTTP GET request
2021-11-19 16:20:45 -05:00

97 lines
2.2 KiB
C++

#pragma once
#include "QueryParams.h"
#include "lib/core/HashPhaser.h"
#include <functional>
#include <ostream>
#include <string>
#include <unordered_set>
#include <variant>
#include <vector>
namespace bts::api::io {
class URL;
}
namespace bts::io {
class URL {
public:
URL() = default;
explicit URL(const bts::api::io::URL &url);
URL(const URL &) = default;
URL(URL &&) noexcept = default;
URL &operator=(const URL &) = default;
URL &operator=(URL &&) noexcept = default;
std::string &protocol();
const std::string &protocol() const;
std::string &host();
const std::string &host() const;
std::uint16_t &port();
std::uint16_t port() const;
std::string &path();
const std::string &path() const;
QueryParams &query_params();
const QueryParams &query_params() const;
std::string to_string() const;
void fill_protocol(const std::string &protocol);
void fill_host(const std::string &host);
void fill_path(const std::string &path);
void fill_port(std::uint16_t port);
void fill_query_params(
const QueryParams &query_params, bool add_missing_params = false);
void fill_with(const URL &url);
static std::uint16_t get_known_port_for_protocol(
const std::string &protocol);
static std::string get_known_protocol_for_port(std::uint16_t port);
private:
std::string protocol_;
std::string host_;
std::uint16_t port_;
std::string path_;
QueryParams query_params_;
static std::vector<std::pair<std::string, std::uint16_t>>
well_known_ports_();
};
bool operator==(const URL &lhs, const URL &rhs) noexcept;
bool operator!=(const URL &lhs, const URL &rhs) noexcept;
std::ostream &operator<<(std::ostream &out, const URL &url) noexcept;
} // namespace bts::io
namespace std {
template <>
struct hash<bts::io::URL> {
std::size_t operator()(const bts::io::URL &url) const;
};
} // namespace std
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
namespace std {
inline std::size_t hash<bts::io::URL>::operator()(
const bts::io::URL &url) const {
return bts::core::HashPhaser::auto_phase(
url.protocol(), url.host(), url.port(), url.path(),
url.query_params().size());
}
} // namespace std