Unverified Commit 1b8a3524 authored by Doron Somech's avatar Doron Somech Committed by GitHub

Merge pull request #3782 from mloy/fix_websocket_without_path_with_test

Fix websocket without path with test
parents 7ea72e56 65ce499b
# Permission to Relicense under MPLv2
This is a statement by Matthias Loy
that grants permission to relicense its copyrights in the libzmq C++
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2).
A portion of the commits made by the Github handle "mloy", with
commit author "Matthias Loy", are copyright of Matthias Loy.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
Matthias Loy
2020/01/18
......@@ -99,14 +99,17 @@ int zmq::ws_address_t::resolve (const char *name_, bool local_, bool ipv6_)
}
_host = std::string (name_, delim - name_);
// find the path part, which is optional
// find the path part, which is optional
delim = strrchr (name_, '/');
if (delim)
std::string host_name;
if (delim) {
_path = std::string (delim);
else
// remove the path, otherwise resolving the port will fail with wildcard
host_name = std::string (name_, delim - name_);
} else {
_path = std::string ("/");
// remove the path, otherwise resolving the port will fail with wildcard
std::string host_port = std::string (name_, delim - name_);
host_name = name_;
}
ip_resolver_options_t resolver_opts;
resolver_opts.bindable (local_)
......@@ -118,7 +121,7 @@ int zmq::ws_address_t::resolve (const char *name_, bool local_, bool ipv6_)
ip_resolver_t resolver (resolver_opts);
return resolver.resolve (&_address, host_port.c_str ());
return resolver.resolve (&_address, host_name.c_str ());
}
int zmq::ws_address_t::to_string (std::string &addr_) const
......
......@@ -212,8 +212,14 @@ int zmq::ws_listener_t::set_local_address (const char *addr_)
// remove the path, otherwise resolving the port will fail with wildcard
const char *delim = strrchr (addr_, '/');
std::string host_port = std::string (addr_, delim - addr_);
if (create_socket (host_port.c_str ()) == -1)
std::string host_address;
if (delim) {
host_address = std::string (addr_, delim - addr_);
} else {
host_address = addr_;
}
if (create_socket (host_address.c_str ()) == -1)
return -1;
}
......
......@@ -52,6 +52,25 @@ void test_roundtrip ()
test_context_socket_close (sb);
}
void test_roundtrip_without_path ()
{
char connect_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (connect_address);
void *sb = test_context_socket (ZMQ_REP);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://*:*"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length));
void *sc = test_context_socket (ZMQ_REQ);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address));
bounce (sb, sc);
test_context_socket_close (sc);
test_context_socket_close (sb);
}
void test_heartbeat ()
{
char connect_address[MAX_SOCKET_STRING + strlen ("/heartbeat")];
......@@ -202,6 +221,7 @@ int main ()
UNITY_BEGIN ();
RUN_TEST (test_roundtrip);
RUN_TEST (test_roundtrip_without_path);
RUN_TEST (test_short_message);
RUN_TEST (test_large_message);
RUN_TEST (test_heartbeat);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment