Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7726ab7

Browse files
committed
Adding the IP information about the requestor to the example, one of the FAQs.
1 parent0af34c7 commit7726ab7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

‎libs/network/doc/hello_world_server.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ simple response to any HTTP request.
1919
..code-block::c++
2020

2121
#include <boost/network/protocol/http/server.hpp>
22+
#include <string>
2223
#include <iostream>
2324

2425
namespace http = boost::network::http;
@@ -29,8 +30,9 @@ simple response to any HTTP request.
2930
struct hello_world {
3031
void operator() (server::request const &request,
3132
server::response &response) {
33+
std::string ip = source(request);
3234
response = server::response::stock_reply(
33-
server::response::ok, "Hello,World!");
35+
server::response::ok,std::string("Hello,") + ip + "!");
3436
}
3537
};
3638

@@ -79,7 +81,7 @@ a command line as follows:
7981

8082
::
8183

82-
shell$ ./hello_world_server 0.0.0.080
84+
shell$ ./hello_world_server 0.0.0.08000
8385

8486
..note::If you're going to run the server on port 80, you may have to run it
8587
as an administrator.
@@ -104,15 +106,19 @@ This header contains all the code needed to develop an HTTP server with
104106
struct hello_world {
105107
void operator () (server::request const &request,
106108
server::response &response) {
109+
std::string ip = source(request);
107110
response = server::response::stock_reply(
108-
server::response::ok, "Hello,World!");
111+
server::response::ok,std::string("Hello,") + ip + "!");
109112
}
110113
};
111114

112115
``hello_world`` is a functor class which handles HTTP requests. All
113116
the operator does here is return an HTTP response with HTTP code 200
114-
and the body ``"Hello, World!"``. There are a number of pre-defined stock
115-
replies differentiated by status code with configurable bodies.
117+
and the body ``"Hello, <ip>!"``. The ``<ip>`` in this case would be
118+
the IP address of the client that made the request.
119+
120+
There are a number of pre-defined stock replies differentiated by
121+
status code with configurable bodies.
116122

117123
All the supported enumeration values for the response status codes can be found
118124
in ``boost/network/protocol/http/impl/response.ipp``.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp