Skip to content

Commit ac45ccd

Browse files
committed
Merge pull request #1 from CovenantEyes/ce-custom
Provide source port number to requests
2 parents d51d6e4 + c0570dd commit ac45ccd

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

boost/network/protocol/http/impl/request.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ namespace http {
157157
typedef vector_type headers_container_type;
158158
typedef boost::uint16_t port_type;
159159
mutable string_type source;
160+
mutable port_type source_port;
160161
mutable string_type method;
161162
mutable string_type destination;
162163
mutable boost::uint8_t http_version_major;
@@ -168,6 +169,7 @@ namespace http {
168169
using std::swap;
169170
swap(method, r.method);
170171
swap(source, r.source);
172+
swap(source_port, r.source_port);
171173
swap(destination, r.destination);
172174
swap(http_version_major, r.http_version_major);
173175
swap(http_version_minor, r.http_version_minor);

boost/network/protocol/http/server/sync_connection.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace boost { namespace network { namespace http {
7979
void handle_read_headers(boost::system::error_code const &ec, size_t bytes_transferred) {
8080
if (!ec) {
8181
request_.source = socket_.remote_endpoint().address().to_string();
82+
request_.source_port = socket_.remote_endpoint().port();
8283
boost::tribool done;
8384
buffer_type::iterator new_start;
8485
tie(done,new_start) = parser_.parse_headers(request_, buffer_.data(), buffer_.data() + bytes_transferred);

libs/network/example/http/hello_world_server.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ struct hello_world {
2929
void operator() (server::request const &request,
3030
server::response &response) {
3131
server::string_type ip = source(request);
32+
unsigned int port = request.source_port;
3233
std::ostringstream data;
33-
data << "Hello, " << ip << "!";
34+
data << "Hello, " << ip << ':' << port << '!';
3435
response = server::response::stock_reply(
3536
server::response::ok, data.str());
3637
}

0 commit comments

Comments
 (0)