ConnectionInfo.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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().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().is_empty())
  31. builder.append('?');
  32. // the query component
  33. builder.append(m_url.query());
  34. return builder.to_deprecated_string();
  35. }
  36. }