2021-04-17 15:20:24 +00:00
|
|
|
/*
|
2021-04-25 09:30:39 +00:00
|
|
|
* Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
|
2021-04-17 15:20:24 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-17 15:20:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWebSocket/ConnectionInfo.h>
|
|
|
|
|
|
|
|
namespace WebSocket {
|
|
|
|
|
2024-03-18 03:22:27 +00:00
|
|
|
ConnectionInfo::ConnectionInfo(URL::URL url)
|
2021-04-17 15:20:24 +00:00
|
|
|
: m_url(move(url))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnectionInfo::is_secure() const
|
|
|
|
{
|
|
|
|
// RFC 6455 Section 3 :
|
|
|
|
// The URI is called "secure" if the scheme component matches "wss" case-insensitively.
|
2023-08-12 04:52:41 +00:00
|
|
|
return m_url.scheme().bytes_as_string_view().equals_ignoring_ascii_case("wss"sv);
|
2021-04-17 15:20:24 +00:00
|
|
|
}
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString ConnectionInfo::resource_name() const
|
2021-04-17 15:20:24 +00:00
|
|
|
{
|
|
|
|
// RFC 6455 Section 3 :
|
|
|
|
// The "resource-name" can be constructed by concatenating the following:
|
|
|
|
StringBuilder builder;
|
|
|
|
// "/" if the path component is empty
|
2024-08-05 04:55:39 +00:00
|
|
|
auto path = URL::percent_decode(m_url.serialize_path());
|
2023-04-14 19:12:03 +00:00
|
|
|
if (path.is_empty())
|
2022-07-11 20:10:18 +00:00
|
|
|
builder.append('/');
|
2021-04-17 15:20:24 +00:00
|
|
|
// The path component
|
2023-04-14 19:12:03 +00:00
|
|
|
builder.append(path);
|
2021-04-17 15:20:24 +00:00
|
|
|
// "?" if the query component is non-empty
|
2023-08-12 07:28:19 +00:00
|
|
|
if (m_url.query().has_value() && !m_url.query()->is_empty()) {
|
2022-07-11 20:10:18 +00:00
|
|
|
builder.append('?');
|
2023-08-12 07:28:19 +00:00
|
|
|
// the query component
|
|
|
|
builder.append(*m_url.query());
|
|
|
|
}
|
2023-12-16 14:19:34 +00:00
|
|
|
return builder.to_byte_string();
|
2021-04-17 15:20:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|