@@ -19,6 +19,7 @@ simple response to any HTTP request.
19
19
.. code-block :: c++
20
20
21
21
#include <boost/network/protocol/http/server.hpp>
22
+ #include <string>
22
23
#include <iostream>
23
24
24
25
namespace http = boost::network: :http;
@@ -29,8 +30,9 @@ simple response to any HTTP request.
29
30
struct hello_world {
30
31
void operator() (server::request const &request,
31
32
server::response &response) {
33
+ std::string ip = source(request);
32
34
response = server::response: :stock_reply(
33
- server::response: :ok, "Hello, World !");
35
+ server::response: :ok, std::string( "Hello, ") + ip + " !");
34
36
}
35
37
};
36
38
@@ -79,7 +81,7 @@ a command line as follows:
79
81
80
82
::
81
83
82
- shell$ ./hello_world_server 0.0.0.0 80
84
+ shell$ ./hello_world_server 0.0.0.0 8000
83
85
84
86
.. note :: If you're going to run the server on port 80, you may have to run it
85
87
as an administrator.
@@ -104,15 +106,19 @@ This header contains all the code needed to develop an HTTP server with
104
106
struct hello_world {
105
107
void operator () (server::request const &request,
106
108
server::response &response) {
109
+ std::string ip = source(request);
107
110
response = server::response: :stock_reply(
108
- server::response: :ok, "Hello, World !");
111
+ server::response: :ok, std::string( "Hello, ") + ip + " !");
109
112
}
110
113
};
111
114
112
115
``hello_world `` is a functor class which handles HTTP requests. All
113
116
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.
116
122
117
123
All the supported enumeration values for the response status codes can be found
118
124
in ``boost/network/protocol/http/impl/response.ipp ``.
0 commit comments