Skip to content

Commit 32abac3

Browse files
authored
Fix ambiguous Get() examples in README after new Params overload (#2486)
* Initial plan * Add Get(path, params) overload to ClientImpl and Client; fix ambiguous test calls * Fix clang-format style errors in test.cc * Fix remaining ambiguous Get() calls in test_proxy.cc and test.cc * Update README Get() examples to disambiguate Headers overload --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 2132205 commit 32abac3

4 files changed

Lines changed: 119 additions & 69 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ auto res = cli.Get("/hi", headers);
996996
or
997997

998998
```c++
999-
auto res = cli.Get("/hi", {{"Hello", "World!"}});
999+
auto res = cli.Get("/hi", httplib::Headers{{"Hello", "World!"}});
10001000
```
10011001
10021002
or
@@ -1240,7 +1240,7 @@ for details and for reading the variable from the environment.
12401240
```cpp
12411241
httplib::Client cli("httpcan.org");
12421242
1243-
auto res = cli.Get("/range/32", {
1243+
auto res = cli.Get("/range/32", httplib::Headers{
12441244
httplib::make_range_header({{1, 10}}) // 'Range: bytes=1-10'
12451245
});
12461246
// res->status should be 206.
@@ -1364,13 +1364,13 @@ The default `Accept-Encoding` value contains all possible compression types. So,
13641364

13651365
```c++
13661366
res = cli.Get("/resource/foo");
1367-
res = cli.Get("/resource/foo", {{"Accept-Encoding", "br, gzip, deflate, zstd"}});
1367+
res = cli.Get("/resource/foo", httplib::Headers{{"Accept-Encoding", "br, gzip, deflate, zstd"}});
13681368
```
13691369
13701370
If we don't want a response without compression, we have to set `Accept-Encoding` to an empty string. This behavior is similar to curl.
13711371
13721372
```c++
1373-
res = cli.Get("/resource/foo", {{"Accept-Encoding", ""}});
1373+
res = cli.Get("/resource/foo", httplib::Headers{{"Accept-Encoding", ""}});
13741374
```
13751375

13761376
### Compress request body on client

httplib.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,7 @@ class ClientImpl {
22192219
Result Get(const std::string &path, const Headers &headers, DownloadProgress progress = nullptr);
22202220
Result Get(const std::string &path, const Headers &headers, ContentReceiver content_receiver, DownloadProgress progress = nullptr);
22212221
Result Get(const std::string &path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, DownloadProgress progress = nullptr);
2222+
Result Get(const std::string &path, const Params &params, DownloadProgress progress = nullptr);
22222223
Result Get(const std::string &path, const Params &params, const Headers &headers, DownloadProgress progress = nullptr);
22232224
Result Get(const std::string &path, const Params &params, const Headers &headers, ContentReceiver content_receiver, DownloadProgress progress = nullptr);
22242225
Result Get(const std::string &path, const Params &params, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, DownloadProgress progress = nullptr);
@@ -2602,6 +2603,7 @@ class Client {
26022603
Result Get(const std::string &path, const Headers &headers, DownloadProgress progress = nullptr);
26032604
Result Get(const std::string &path, const Headers &headers, ContentReceiver content_receiver, DownloadProgress progress = nullptr);
26042605
Result Get(const std::string &path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, DownloadProgress progress = nullptr);
2606+
Result Get(const std::string &path, const Params &params, DownloadProgress progress = nullptr);
26052607
Result Get(const std::string &path, const Params &params, const Headers &headers, DownloadProgress progress = nullptr);
26062608
Result Get(const std::string &path, const Params &params, const Headers &headers, ContentReceiver content_receiver, DownloadProgress progress = nullptr);
26072609
Result Get(const std::string &path, const Params &params, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, DownloadProgress progress = nullptr);
@@ -14284,6 +14286,11 @@ inline Result ClientImpl::Get(const std::string &path,
1428414286
return Get(path, Headers(), std::move(progress));
1428514287
}
1428614288

14289+
inline Result ClientImpl::Get(const std::string &path, const Params &params,
14290+
DownloadProgress progress) {
14291+
return Get(path, params, Headers(), std::move(progress));
14292+
}
14293+
1428714294
inline Result ClientImpl::Get(const std::string &path, const Params &params,
1428814295
const Headers &headers,
1428914296
DownloadProgress progress) {
@@ -15362,6 +15369,10 @@ inline Result Client::Get(const std::string &path, const Headers &headers,
1536215369
return cli_->Get(path, headers, std::move(response_handler),
1536315370
std::move(content_receiver), std::move(progress));
1536415371
}
15372+
inline Result Client::Get(const std::string &path, const Params &params,
15373+
DownloadProgress progress) {
15374+
return cli_->Get(path, params, std::move(progress));
15375+
}
1536515376
inline Result Client::Get(const std::string &path, const Params &params,
1536615377
const Headers &headers, DownloadProgress progress) {
1536715378
return cli_->Get(path, params, headers, std::move(progress));

0 commit comments

Comments
 (0)