Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/sync_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import subprocess

HTTPLIB_VERSION = "refs/tags/v0.40.0"
HTTPLIB_VERSION = "refs/tags/v0.41.0"

vendor = {
"https://github.com/nlohmann/json/releases/latest/download/json.hpp": "vendor/nlohmann/json.hpp",
Expand Down
58 changes: 24 additions & 34 deletions vendor/cpp-httplib/httplib.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "httplib.h"
namespace httplib {
// httplib::any — type-erased value container (C++11 compatible)
// On C++17+ builds, thin wrappers around std::any are provided.

/*
* Implementation that will be part of the .cc file if split into .h + .cc.
Expand Down Expand Up @@ -9119,20 +9117,21 @@ bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
auto location = res.get_header_value("location");
if (location.empty()) { return false; }

thread_local const std::regex re(
R"((?:(https?):)?(?://(?:\[([a-fA-F\d:]+)\]|([^:/?#]+))(?::(\d+))?)?([^?#]*)(\?[^#]*)?(?:#.*)?)");
detail::UrlComponents uc;
if (!detail::parse_url(location, uc)) { return false; }

std::smatch m;
if (!std::regex_match(location, m, re)) { return false; }
// Only follow http/https redirects
if (!uc.scheme.empty() && uc.scheme != "http" && uc.scheme != "https") {
return false;
}

auto scheme = is_ssl() ? "https" : "http";

auto next_scheme = m[1].str();
auto next_host = m[2].str();
if (next_host.empty()) { next_host = m[3].str(); }
auto port_str = m[4].str();
auto next_path = m[5].str();
auto next_query = m[6].str();
auto next_scheme = std::move(uc.scheme);
auto next_host = std::move(uc.host);
auto port_str = std::move(uc.port);
auto next_path = std::move(uc.path);
auto next_query = std::move(uc.query);

auto next_port = port_;
if (!port_str.empty()) {
Expand All @@ -9145,7 +9144,7 @@ bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
if (next_host.empty()) { next_host = host_; }
if (next_path.empty()) { next_path = "/"; }

auto path = decode_query_component(next_path, true) + next_query;
auto path = decode_path_component(next_path) + next_query;

// Same host redirect - use current client
if (next_scheme == scheme && next_host == host_ && next_port == port_) {
Expand Down Expand Up @@ -10869,12 +10868,9 @@ Client::Client(const std::string &scheme_host_port)
Client::Client(const std::string &scheme_host_port,
const std::string &client_cert_path,
const std::string &client_key_path) {
const static std::regex re(
R"((?:([a-z]+):\/\/)?(?:\[([a-fA-F\d:]+)\]|([^:/?#]+))(?::(\d+))?)");

std::smatch m;
if (std::regex_match(scheme_host_port, m, re)) {
auto scheme = m[1].str();
detail::UrlComponents uc;
if (detail::parse_url(scheme_host_port, uc) && !uc.host.empty()) {
auto &scheme = uc.scheme;

#ifdef CPPHTTPLIB_SSL_ENABLED
if (!scheme.empty() && (scheme != "http" && scheme != "https")) {
Expand All @@ -10890,12 +10886,10 @@ Client::Client(const std::string &scheme_host_port,

auto is_ssl = scheme == "https";

auto host = m[2].str();
if (host.empty()) { host = m[3].str(); }
auto host = std::move(uc.host);

auto port_str = m[4].str();
auto port = is_ssl ? 443 : 80;
if (!port_str.empty() && !detail::parse_port(port_str, port)) { return; }
if (!uc.port.empty() && !detail::parse_port(uc.port, port)) { return; }

if (is_ssl) {
#ifdef CPPHTTPLIB_SSL_ENABLED
Expand Down Expand Up @@ -16302,12 +16296,10 @@ bool WebSocket::is_open() const { return !closed_; }
WebSocketClient::WebSocketClient(
const std::string &scheme_host_port_path, const Headers &headers)
: headers_(headers) {
const static std::regex re(
R"(([a-z]+):\/\/(?:\[([a-fA-F\d:]+)\]|([^:/?#]+))(?::(\d+))?(\/.*))");

std::smatch m;
if (std::regex_match(scheme_host_port_path, m, re)) {
auto scheme = m[1].str();
detail::UrlComponents uc;
if (detail::parse_url(scheme_host_port_path, uc) && !uc.scheme.empty() &&
!uc.host.empty() && !uc.path.empty()) {
auto &scheme = uc.scheme;

#ifdef CPPHTTPLIB_SSL_ENABLED
if (scheme != "ws" && scheme != "wss") {
Expand All @@ -16323,14 +16315,12 @@ WebSocketClient::WebSocketClient(

auto is_ssl = scheme == "wss";

host_ = m[2].str();
if (host_.empty()) { host_ = m[3].str(); }
host_ = std::move(uc.host);

auto port_str = m[4].str();
port_ = is_ssl ? 443 : 80;
if (!port_str.empty() && !detail::parse_port(port_str, port_)) { return; }
if (!uc.port.empty() && !detail::parse_port(uc.port, port_)) { return; }

path_ = m[5].str();
path_ = std::move(uc.path);

#ifdef CPPHTTPLIB_SSL_ENABLED
is_ssl_ = is_ssl;
Expand Down
Loading
Loading