added use_tls (determine from URL, whether TLS is used)

pull/2/head
Falk Werner 5 years ago
parent d18150d305
commit 9f468f600e

@ -8,6 +8,7 @@ struct wsfsp_url_protocol
char const * name;
size_t name_length;
int default_port;
bool use_tls;
};
static bool wsfsp_url_readprotocol(
@ -16,8 +17,8 @@ static bool wsfsp_url_readprotocol(
{
static struct wsfsp_url_protocol const known_protocols[] =
{
{"ws://", 5, 80},
{"wss://", 6, 443}
{"ws://", 5, 80, false},
{"wss://", 6, 443, true}
};
static size_t const count = (sizeof(known_protocols) / sizeof(known_protocols[0]));
@ -28,6 +29,7 @@ static bool wsfsp_url_readprotocol(
if (0 == strncmp(*data, protocol->name, protocol->name_length))
{
url->port = protocol->default_port;
url->use_tls = protocol->use_tls;
*data = *data + protocol->name_length;
found = true;
}

@ -10,6 +10,7 @@ struct wsfsp_url
char * host;
int port;
char * path;
bool use_tls;
};
#ifdef __cplusplus

@ -8,6 +8,7 @@ TEST(url, ParseWs)
bool result = wsfsp_url_init(&url, "ws://localhost/");
ASSERT_TRUE(result);
ASSERT_EQ(80, url.port);
ASSERT_FALSE(url.use_tls);
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
@ -20,6 +21,7 @@ TEST(url, ParswWss)
bool result = wsfsp_url_init(&url, "wss://localhost/");
ASSERT_TRUE(result);
ASSERT_EQ(443, url.port);
ASSERT_TRUE(url.use_tls);
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
@ -81,7 +83,7 @@ TEST(url, FailToParseMissingProtocol)
TEST(url, FailToParseMissingPath)
{
struct wsfsp_url url;
bool result = wsfsp_url_init(&url, "wss://localhost");
bool result = wsfsp_url_init(&url, "ws://localhost");
ASSERT_FALSE(result);
ASSERT_EQ(0, url.port);
ASSERT_EQ(nullptr, url.path);

Loading…
Cancel
Save