Skip to content

Commit c717aae

Browse files
author
pfeatherstone
committed
trying to fix MSVC build
1 parent b352aa5 commit c717aae

File tree

7 files changed

+67
-43
lines changed

7 files changed

+67
-43
lines changed

examples/client_http.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ awaitable_strand http_session(std::string_view host)
6363
size_t ret{};
6464

6565
// Prepare request
66-
req.verb = http::GET;
66+
req.verb = http::METHOD_GET;
6767
req.uri = "/get";
6868
req.add_header(http::host, host); // mandatory in HTTP/1.1 in request messages
6969
req.add_header(http::user_agent, "Boost::asio " + std::to_string(BOOST_ASIO_VERSION)); // optional header

examples/server.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ struct api_options
7979
return str;
8080
}
8181

82-
constexpr auto split_once(std::string_view str, std::string_view chrs)
82+
constexpr auto split_once(std::string_view str, char c)
8383
{
84-
auto pos = str.find(chrs);
85-
84+
auto pos = str.find(c);
8685
std::string_view first = str.substr(0, pos);
87-
std::string_view second = str.substr(pos+chrs.size());
88-
86+
std::string_view second = str.substr(pos+1);
8987
return std::make_pair(first, second);
9088
}
9189

@@ -155,9 +153,9 @@ auto handle_authorization (const http::request& req, std::string_view username_e
155153
std::string_view login_base64 = lskip(field->value, "Basic ");
156154
const auto login = http::base64_decode(login_base64);
157155

158-
const auto [user, passwd] = split_once(std::string_view((const char*)&login[0], login.size()), ":");
156+
const auto [user, passwd] = split_once(std::string_view((const char*)&login[0], login.size()), ':');
159157

160-
if (user.compare(username_exp) != 0 || passwd.compare(passwd_exp) != 0)
158+
if (user != username_exp || passwd != passwd_exp)
161159
return std::make_pair(false, "Authentication username-password don't match expected");
162160

163161
return std::make_pair(true, "Authenticated!");
@@ -173,9 +171,9 @@ void handle_request (
173171
)
174172
{
175173
// Make sure we can handle the method
176-
if( req.verb != http::GET &&
177-
req.verb != http::POST &&
178-
req.verb != http::PUT)
174+
if( req.verb != http::METHOD_GET &&
175+
req.verb != http::METHOD_POST &&
176+
req.verb != http::METHOD_PUT)
179177
return http_bad_request(req, resp, "Unknown HTTP-method");
180178

181179
// Check the HTTP request is authorized
@@ -399,7 +397,7 @@ awaitable listen (
399397
if (options.use_tls)
400398
{
401399
printf("Open https://localhost:%hu\n", options.port);
402-
ssl = std::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv13_server);
400+
ssl = std::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv12_server);
403401
ssl->set_options(
404402
boost::asio::ssl::context::default_workarounds |
405403
boost::asio::ssl::context::no_sslv2 |

examples/unit_tests/async.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST_SUITE("[ASYNC]")
3636
std::string buf_client;
3737
std::string buf_peer;
3838

39-
req_client.verb = http::GET;
39+
req_client.verb = http::METHOD_GET;
4040
req_client.uri = "/data?name=bane&code=Peace+is+a+lie.+There+is+only+Passion.";
4141
req_client.add_header(http::host, "hello there!");
4242
req_client.add_header(http::user_agent, "Boost::asio " + std::to_string(BOOST_ASIO_VERSION)); // optional header
@@ -138,7 +138,7 @@ TEST_SUITE("[ASYNC]")
138138
}
139139

140140
REQUIRE(!exception_thrown);
141-
REQUIRE(req_peer.verb == http::GET);
141+
REQUIRE(req_peer.verb == http::METHOD_GET);
142142
REQUIRE(req_peer.uri == "/data");
143143
REQUIRE(req_peer.params.size() == 2);
144144
REQUIRE(req_peer.params[0].key == "name");
@@ -161,4 +161,30 @@ TEST_SUITE("[ASYNC]")
161161
REQUIRE(resp_peer.headers[i].value == resp_client.headers[i].value);
162162
}
163163
}
164+
165+
TEST_CASE("WEBSOCKET")
166+
{
167+
boost::asio::io_context ioc{1};
168+
tcp_acceptor acceptor(ioc, {tcp::v4(), 6666});
169+
tcp_socket peer(ioc);
170+
tcp_socket client(ioc);
171+
tcp_resolver resolver(ioc);
172+
bool exception_thrown{false};
173+
174+
std::vector<uint8_t> data_peer;
175+
std::vector<uint8_t> data_client;
176+
std::string text_peer;
177+
std::string text_client;
178+
179+
try
180+
{
181+
182+
}
183+
catch(const std::exception& e)
184+
{
185+
exception_thrown = true;
186+
}
187+
188+
REQUIRE(!exception_thrown);
189+
}
164190
}

examples/unit_tests/message.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ TEST_SUITE("[MESSAGE]")
6767
{
6868
TEST_CASE("enums")
6969
{
70-
REQUIRE(http::verb_enum(http::verb_label(http::UNKNOWN_VERB)) == http::UNKNOWN_VERB);
71-
REQUIRE(http::verb_enum(http::verb_label(http::GET)) == http::GET);
72-
REQUIRE(http::verb_enum(http::verb_label(http::HEAD)) == http::HEAD);
73-
REQUIRE(http::verb_enum(http::verb_label(http::POST)) == http::POST);
74-
REQUIRE(http::verb_enum(http::verb_label(http::PUT)) == http::PUT);
75-
REQUIRE(http::verb_enum(http::verb_label(http::DELETE)) == http::DELETE);
76-
REQUIRE(http::verb_enum(http::verb_label(http::CONNECT)) == http::CONNECT);
77-
REQUIRE(http::verb_enum(http::verb_label(http::OPTIONS)) == http::OPTIONS);
78-
REQUIRE(http::verb_enum(http::verb_label(http::TRACE)) == http::TRACE);
79-
REQUIRE(http::verb_enum(http::verb_label(http::PATCH)) == http::PATCH);
70+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_UNKNOWN)) == http::METHOD_UNKNOWN);
71+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_GET)) == http::METHOD_GET);
72+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_HEAD)) == http::METHOD_HEAD);
73+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_POST)) == http::METHOD_POST);
74+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_PUT)) == http::METHOD_PUT);
75+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_DELETE)) == http::METHOD_DELETE);
76+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_CONNECT)) == http::METHOD_CONNECT);
77+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_OPTIONS)) == http::METHOD_OPTIONS);
78+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_TRACE)) == http::METHOD_TRACE);
79+
REQUIRE(http::verb_enum(http::verb_label(http::METHOD_PATCH)) == http::METHOD_PATCH);
8080

8181
for (unsigned int f = http::unknown_field ; f <= http::xref ; ++f)
8282
REQUIRE(http::field_enum(http::field_label((http::field)f)) == f);
@@ -111,12 +111,12 @@ TEST_SUITE("[MESSAGE]")
111111

112112
SUBCASE("missing uri")
113113
{
114-
req.verb = http::GET;
114+
req.verb = http::METHOD_GET;
115115
}
116116

117117
SUBCASE("missing host")
118118
{
119-
req.verb = http::GET;
119+
req.verb = http::METHOD_GET;
120120
req.uri = "/index";
121121
}
122122

@@ -139,7 +139,7 @@ TEST_SUITE("[MESSAGE]")
139139
TEST_CASE("serialize & parse good request")
140140
{
141141
http::request req0;
142-
req0.verb = http::GET;
142+
req0.verb = http::METHOD_GET;
143143
req0.uri = "/path/to/resource/with+spaces";
144144
req0.add_header(http::host, "www.example.com:8080");
145145
req0.add_header(http::user_agent, "CustomTestAgent/7.4.2 (compatible; FancyBot/1.0; +https://example.com/bot)");

src/http.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace http
3737
for (unsigned int i = 0 ; i < std::size(VERBS) ; ++i)
3838
if (VERBS[i] == str)
3939
return (verb_type)i;
40-
return UNKNOWN_VERB;
40+
return METHOD_UNKNOWN;
4141
}
4242

4343
//----------------------------------------------------------------------------------------------------------------
@@ -883,7 +883,7 @@ namespace http
883883
headers.clear();
884884
content.clear();
885885
version = {};
886-
verb = UNKNOWN_VERB;
886+
verb = METHOD_UNKNOWN;
887887
}
888888

889889
void request::add_header(field f, std::string_view value)
@@ -999,7 +999,7 @@ namespace http
999999
const verb_type method = verb_enum(method_str.substr(0, end));
10001000

10011001
// Found
1002-
if (method != UNKNOWN_VERB)
1002+
if (method != METHOD_UNKNOWN)
10031003
{
10041004
if constexpr (std::is_same_v<Message, request>)
10051005
msg.verb = method;
@@ -1265,7 +1265,7 @@ namespace http
12651265
void serialize_header(request& req, std::string& buf, std::error_code& ec)
12661266
{
12671267
// Check request
1268-
if (req.verb == UNKNOWN_VERB)
1268+
if (req.verb == METHOD_UNKNOWN)
12691269
{
12701270
ec = make_error_code(http::http_write_request_bad_verb);
12711271
return;

src/http.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ namespace http
2222

2323
enum verb_type : unsigned int
2424
{
25-
UNKNOWN_VERB = 0,
26-
GET,
27-
HEAD,
28-
POST,
29-
PUT,
30-
DELETE,
31-
CONNECT,
32-
OPTIONS,
33-
TRACE,
34-
PATCH
25+
METHOD_UNKNOWN = 0,
26+
METHOD_GET,
27+
METHOD_HEAD,
28+
METHOD_POST,
29+
METHOD_PUT,
30+
METHOD_DELETE,
31+
METHOD_CONNECT,
32+
METHOD_OPTIONS,
33+
METHOD_TRACE,
34+
METHOD_PATCH
3535
};
3636

3737
//----------------------------------------------------------------------------------------------------------------
@@ -539,7 +539,7 @@ namespace http
539539

540540
struct request
541541
{
542-
verb_type verb{UNKNOWN_VERB};
542+
verb_type verb{METHOD_UNKNOWN};
543543
http_version version{HTTP_1_1};
544544
std::string uri;
545545
std::vector<query_param> params;

src/http_async.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ namespace http
528528
for (size_t i{0} ; i < 16 ; ++i)
529529
nonce[i] = std::rand() % 0xff;
530530

531-
req->verb = GET;
531+
req->verb = METHOD_GET;
532532
req->uri = uri;
533533
req->add_header(field::host, host);
534534
req->add_header(field::user_agent, "Boost::asio " + std::to_string(BOOST_ASIO_VERSION));

0 commit comments

Comments
 (0)