ConnectionInfo.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWebSocket/ConnectionInfo.h>
  7. namespace WebSocket {
  8. ConnectionInfo::ConnectionInfo(URL url)
  9. : m_url(move(url))
  10. {
  11. }
  12. bool ConnectionInfo::is_secure() const
  13. {
  14. // RFC 6455 Section 3 :
  15. // The URI is called "secure" if the scheme component matches "wss" case-insensitively.
  16. return m_url.scheme().bytes_as_string_view().equals_ignoring_ascii_case("wss"sv);
  17. }
  18. DeprecatedString ConnectionInfo::resource_name() const
  19. {
  20. // RFC 6455 Section 3 :
  21. // The "resource-name" can be constructed by concatenating the following:
  22. StringBuilder builder;
  23. // "/" if the path component is empty
  24. auto path = m_url.serialize_path();
  25. if (path.is_empty())
  26. builder.append('/');
  27. // The path component
  28. builder.append(path);
  29. // "?" if the query component is non-empty
  30. if (m_url.query().has_value() && !m_url.query()->is_empty()) {
  31. builder.append('?');
  32. // the query component
  33. builder.append(*m_url.query());
  34. }
  35. return builder.to_deprecated_string();
  36. }
  37. }