ConnectionInfo.cpp 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.protocol().equals_ignoring_case("wss"sv);
  17. }
  18. String 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. if (m_url.path().is_empty())
  25. builder.append("/");
  26. // The path component
  27. builder.append(m_url.path());
  28. // "?" if the query component is non-empty
  29. if (!m_url.query().is_empty())
  30. builder.append("?");
  31. // the query component
  32. builder.append(m_url.query());
  33. return builder.to_string();
  34. }
  35. }