@@ -766,7 +766,7 @@ class Client {
766766private:
767767 socket_t create_client_socket () const ;
768768 bool read_response_line (Stream &strm, Response &res);
769- void write_request (Stream &strm, const Request &req, bool last_connection);
769+ bool write_request (Stream &strm, const Request &req, bool last_connection);
770770 bool redirect (const Request &req, Response &res);
771771
772772 std::shared_ptr<Response> send_with_content_provider (
@@ -3490,8 +3490,6 @@ inline bool Client::redirect(const Request &req, Response &res) {
34903490 std::regex re (
34913491 R"( ^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*(?:\?[^#]*)?)(?:#.*)?)" );
34923492
3493- auto scheme = is_ssl () ? " https" : " http" ;
3494-
34953493 std::smatch m;
34963494 if (regex_match (location, m, re)) {
34973495 auto next_scheme = m[1 ].str ();
@@ -3500,6 +3498,8 @@ inline bool Client::redirect(const Request &req, Response &res) {
35003498 if (next_host.empty ()) { next_host = host_; }
35013499 if (next_path.empty ()) { next_path = " /" ; }
35023500
3501+ auto scheme = is_ssl () ? " https" : " http" ;
3502+
35033503 if (next_scheme == scheme && next_host == host_) {
35043504 return detail::redirect (*this , req, res, next_path);
35053505 } else {
@@ -3521,12 +3521,20 @@ inline bool Client::redirect(const Request &req, Response &res) {
35213521 return false ;
35223522}
35233523
3524- inline void Client::write_request (Stream &strm, const Request &req,
3524+ inline bool Client::write_request (Stream &strm, const Request &req,
35253525 bool last_connection) {
35263526 BufferStream bstrm;
35273527
35283528 // Request line
3529- auto path = detail::encode_url (req.path );
3529+ static std::regex re (
3530+ R"( ^([^:/?#]+://[^/?#]*)?([^?#]*(?:\?[^#]*)?(?:#.*)?))" );
3531+
3532+ std::smatch m;
3533+ if (!regex_match (req.path , m, re)) {
3534+ return false ;
3535+ }
3536+
3537+ auto path = m[1 ].str () + detail::encode_url (m[2 ].str ());
35303538
35313539 bstrm.write_format (" %s %s HTTP/1.1\r\n " , req.method .c_str (), path.c_str ());
35323540
@@ -3596,6 +3604,8 @@ inline void Client::write_request(Stream &strm, const Request &req,
35963604 } else {
35973605 strm.write (req.body );
35983606 }
3607+
3608+ return true ;
35993609}
36003610
36013611inline std::shared_ptr<Response> Client::send_with_content_provider (
@@ -3646,7 +3656,9 @@ inline bool Client::process_request(Stream &strm, const Request &req,
36463656 Response &res, bool last_connection,
36473657 bool &connection_close) {
36483658 // Send request
3649- write_request (strm, req, last_connection);
3659+ if (!write_request (strm, req, last_connection)) {
3660+ return false ;
3661+ }
36503662
36513663 // Receive response and headers
36523664 if (!read_response_line (strm, res) ||
0 commit comments