Skip to content

Commit a912ab9

Browse files
committed
Supporting Custom Ports in Host Header for Requests
This commit addresses mikhailberis/cpp-netlib#25 which puts the port as part of the Host header in HTTP requests.
1 parent ec4689a commit a912ab9

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

boost/network/protocol/http/algorithms/linearize.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <boost/network/protocol/http/request_concept.hpp>
1414
#include <boost/network/constants.hpp>
1515
#include <boost/concept/requires.hpp>
16+
#include <boost/optional.hpp>
1617
#include <boost/range/algorithm/copy.hpp>
1718

1819
namespace boost { namespace network { namespace http {
@@ -95,6 +96,12 @@ namespace boost { namespace network { namespace http {
9596
*oi = consts::colon_char();
9697
*oi = consts::space_char();
9798
boost::copy(request.host(), oi);
99+
boost::optional<boost::uint16_t> port_ = port(request);
100+
if (port_) {
101+
string_type port_str = boost::lexical_cast<string_type>(*port_);
102+
*oi = consts::colon_char();
103+
boost::copy(port_str, oi);
104+
}
98105
boost::copy(crlf, oi);
99106
boost::copy(accept, oi);
100107
*oi = consts::colon_char();

boost/network/protocol/http/message/wrappers/port.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10+
#include <boost/optional.hpp>
11+
1012
namespace boost { namespace network { namespace http {
1113

1214
template <class Tag>
@@ -26,6 +28,10 @@ namespace boost { namespace network { namespace http {
2628
operator port_type() {
2729
return message_.port();
2830
}
31+
32+
operator boost::optional<boost::uint16_t> () {
33+
return port(message_.uri());
34+
}
2935
};
3036

3137
} // namespace impl

boost/network/protocol/http/message/wrappers/uri.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10+
#include <boost/network/uri/http/uri.hpp>
11+
1012
namespace boost { namespace network { namespace http {
1113

1214
template <class Tag>
@@ -22,6 +24,9 @@ namespace boost { namespace network { namespace http {
2224
operator string_type() {
2325
return message_.uri().raw();
2426
}
27+
operator boost::network::uri::basic_uri<tags::http_default_8bit_tcp_resolve> () {
28+
return message_.uri();
29+
}
2530
};
2631
}
2732

0 commit comments

Comments
 (0)