mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-08-12 05:11:24 +00:00
ClientImpl::open_stream() passed the caller-supplied path straight to the request line, so it ignored path_encode_ entirely and always behaved as if set_path_encode(false) had been called. The same path therefore produced different bytes on the wire depending on which API was used: Get() "/a b" -> GET /a%20b HTTP/1.1 open_stream() "/a b" -> GET /a b HTTP/1.1 A space is the request-target delimiter, so the streaming form is not merely inconsistent: an RFC 9112 conformant server reads the target as "/a" and the version as "b". Non-ASCII bytes and '+' diverged the same way, the latter changing the value a server that decodes '+' as space sees. Extract the path/query splitting and encoding out of ClientImpl::write_request into detail::encode_request_target() and call it from both paths, so the encoding rule lives in one place. open_stream() appends Params before encoding, matching ClientImpl::Get(path, params), which builds its target the same way. Note a behavior change: with path encoding enabled, CR/LF in the target is now percent-encoded and sent rather than rejected with Error::Write, matching Get(). This is not a weakening of the CR/LF guard in write_request_line() -- that check is independent of path_encode_ and still backstops set_path_encode(false), where encode_path() does nothing.