@@ -27,15 +27,12 @@ simple response to any HTTP request.
27
27
typedef http::server<hello_world> server;
28
28
29
29
struct hello_world {
30
- void operator()(server::request const &request, server::response &response ) {
30
+ void operator()(server::request const &request, server::connection_ptr connection ) {
31
31
server::string_type ip = source(request);
32
32
unsigned int port = request.source_port;
33
33
std::ostringstream data;
34
34
data << "Hello, " << ip << ':' << port << '!';
35
- response = server::response: :stock_reply(server::response: :ok, data.str());
36
- }
37
- void log(const server::string_type& message) {
38
- std::cerr << "ERROR: " << message << std::endl;
35
+ connection->write(data.str());
39
36
}
40
37
};
41
38
@@ -103,22 +100,21 @@ This header contains all the code needed to develop an HTTP server with
103
100
typedef http::server<hello_world> server;
104
101
105
102
struct hello_world {
106
- void operator()(server::request const &request, server::response &response ) {
103
+ void operator()(server::request const &request, server::connection_ptr connection ) {
107
104
server::string_type ip = source(request);
108
105
unsigned int port = request.source_port;
109
106
std::ostringstream data;
110
107
data << "Hello, " << ip << ':' << port << '!';
111
- response = server::response: :stock_reply(server::response: :ok, data.str());
112
- }
113
- void log(const server::string_type& message) {
114
- std::cerr << "ERROR: " << message << std::endl;
108
+ connection->write(data.str());
115
109
}
116
110
};
117
111
118
112
``hello_world `` is a functor class which handles HTTP requests.
119
113
All the operator does here is return an HTTP response with HTTP code 200
120
114
and the body ``"Hello, <ip>:<port>!" ``. The ``<ip> `` in this case would be
121
115
the IP address of the client that made the request and ``<port> `` the clients port.
116
+ If you like to send an other status have a look at the function
117
+ ``set_status(status_t status) `` from connection.
122
118
123
119
There are a number of pre-defined stock replies differentiated by
124
120
status code with configurable bodies.
0 commit comments