Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire committed Nov 22, 2023
1 parent d331dca commit b10facf
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/cpprealm/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

namespace realm {
using proxy_config = sync_config::proxy_config;
using proxy_config_type = sync_config::proxy_config::Type;
using sync_session = internal::bridge::sync_session;
class SyncUser;

Expand Down
9 changes: 1 addition & 8 deletions src/cpprealm/internal/bridge/realm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,7 @@ namespace realm::internal::bridge {
SyncConfig::ProxyConfig core_config;
core_config.address = config.address;
core_config.port = config.port;
switch (config.type) {
case sync_config::proxy_config::Type::HTTP:
core_config.type = SyncConfig::ProxyConfig::Type::HTTP;
break;
case sync_config::proxy_config::Type::HTTPS:
core_config.type = SyncConfig::ProxyConfig::Type::HTTPS;
break;
}
core_config.type = SyncConfig::ProxyConfig::Type::HTTP;
get_config()->sync_config->proxy_config = std::move(core_config);
} else {
throw std::logic_error("Proxy configuration can only be set on a config for a synced Realm.");
Expand Down
1 change: 0 additions & 1 deletion src/cpprealm/internal/bridge/realm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace realm::internal::bridge {

struct proxy_config {
using port_type = std::uint_fast16_t;
enum class Type { HTTP, HTTPS } type;
std::string address;
port_type port;
// For basic authorization.
Expand Down
21 changes: 3 additions & 18 deletions src/cpprealm/internal/network/network_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <realm/sync/network/network.hpp>
#include <realm/sync/noinst/client_impl_base.hpp>
#include <realm/util/base64.hpp>
#include <realm/util/uri.hpp>

#include <regex>

Expand Down Expand Up @@ -82,20 +83,9 @@ namespace realm::internal {
realm::sync::network::ReadAheadBuffer m_read_buffer;
};

inline std::string host_from_url(const std::string& url) {
std::regex pattern("^(https?://)?([a-zA-Z0-9.-]+|\\[?[0-9a-fA-F:]+\\]?)(:[0-9]+)?(/.*)?$");
std::smatch matches;
if (std::regex_search(url, matches, pattern)) {
if (matches.size() > 2) {
return matches[2].str();
}
}
return "";
}

void DefaultTransport::send_request_to_server(const app::Request& request,
util::UniqueFunction<void(const app::Response&)>&& completion_block) {
std::string host = host_from_url(request.url);
std::string host = realm::util::Uri(request.url).get_auth();

realm::sync::network::Service service;
using namespace realm::sync::network::ssl;
Expand All @@ -106,7 +96,7 @@ namespace realm::internal {
realm::sync::network::Endpoint ep;
auto resolver = realm::sync::network::Resolver{service};
if (m_proxy_config) {
std::string proxy_address = host_from_url(m_proxy_config->address);
std::string proxy_address = realm::util::Uri(m_proxy_config->address).get_auth();
if (proxy_address.empty()) {
std::error_code e;
auto address = realm::sync::network::make_address(m_proxy_config->address, e);
Expand Down Expand Up @@ -147,11 +137,6 @@ namespace realm::internal {
realm::util::base64_encode(userpass.data(), userpass.size(), encoded_userpass.data(), encoded_userpass.size());
req.headers.emplace("Proxy-Authorization", util::format("Basic %1", encoded_userpass));
}
if (m_custom_http_headers) {
for (auto& header : *m_custom_http_headers) {
req.headers.emplace(header);
}
}
realm::sync::HTTPClient<DefaultSocket> m_proxy_client = realm::sync::HTTPClient<DefaultSocket>(socket, logger);
auto handler = [&](realm::sync::HTTPResponse response, std::error_code ec) {
if (ec && ec != util::error::operation_aborted) {
Expand Down

0 comments on commit b10facf

Please sign in to comment.