Skip to content

Commit 5b943d9

Browse files
authored
Use StatusCode in tests and examples (#1743)
* Use StatusCode in tests and examples * Use StatusCode in README
1 parent c86f69a commit 5b943d9

File tree

4 files changed

+297
-292
lines changed

4 files changed

+297
-292
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ svr.set_exception_handler([](const auto& req, auto& res, std::exception_ptr ep)
235235
snprintf(buf, sizeof(buf), fmt, "Unknown Exception");
236236
}
237237
res.set_content(buf, "text/html");
238-
res.status = 500;
238+
res.status = StatusCode::InternalServerError_500;
239239
});
240240
```
241241

@@ -385,14 +385,14 @@ By default, the server sends a `100 Continue` response for an `Expect: 100-conti
385385
```cpp
386386
// Send a '417 Expectation Failed' response.
387387
svr.set_expect_100_continue_handler([](const Request &req, Response &res) {
388-
return 417;
388+
return StatusCode::ExpectationFailed_417;
389389
});
390390
```
391391

392392
```cpp
393393
// Send a final status without reading the message body.
394394
svr.set_expect_100_continue_handler([](const Request &req, Response &res) {
395-
return res.status = 401;
395+
return res.status = StatusCode::Unauthorized_401;
396396
});
397397
```
398398

@@ -473,7 +473,7 @@ int main(void)
473473
httplib::Client cli("localhost", 1234);
474474

475475
if (auto res = cli.Get("/hi")) {
476-
if (res->status == 200) {
476+
if (res->status == StatusCode::OK_200) {
477477
std::cout << res->body << std::endl;
478478
}
479479
} else {
@@ -623,7 +623,7 @@ std::string body;
623623
auto res = cli.Get(
624624
"/stream", Headers(),
625625
[&](const Response &response) {
626-
EXPECT_EQ(200, response.status);
626+
EXPECT_EQ(StatusCode::OK_200, response.status);
627627
return true; // return 'false' if you want to cancel the request.
628628
},
629629
[&](const char *data, size_t data_length) {

example/benchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(void) {
2626
for (int i = 0; i < 3; i++) {
2727
StopWatch sw(to_string(i).c_str());
2828
auto res = cli.Post("/post", body, "application/octet-stream");
29-
assert(res->status == 200);
29+
assert(res->status == httplib::StatusCode::OK_200);
3030
}
3131

3232
return 0;

0 commit comments

Comments
 (0)