Skip to content

Commit d38ec43

Browse files
author
shaoqi
committed
fix content-length bug and client option timeout
1 parent 98738db commit d38ec43

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ sudo apt-get install libssl-dev
3333
通过命令行编译:
3434

3535
```bash
36+
cd cpp-netlib-0.12.0-final
3637
mkdir build
3738
cd build
3839

http_client/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ int main() {
1111
try {
1212
//! 1. request
1313
// client
14-
http::client client;
14+
http::client::options options;
15+
// set timeout
16+
http::client client(options.timeout(2));
1517
// make url
1618
uri::uri url;
1719
url << uri::scheme("http") << uri::host("127.0.0.1:12345") << uri::path("/cpp-netlib");

http_server/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ struct hello_world {
5050
{"Content-Type", "text/plain"},
5151
{"From", "server-demo"},
5252
{"Content-Length", "0"}};
53+
// 更新content-length
54+
std::string body = "hello !!!";
55+
headers[3].value = std::to_string(body.length());
5356

5457
// status
5558
connection->set_status(server::connection::ok);
5659
// headers
5760
connection->set_headers(boost::make_iterator_range(headers, headers + 4));
5861

59-
// 更新content-length
60-
std::string body = "hello !!!";
61-
headers[3].value = std::to_string(body.length());
6262
// body
6363
connection->write(body);
6464
}

0 commit comments

Comments
 (0)