NetworkPartitionKey.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Fetch/Infrastructure/NetworkPartitionKey.h>
  7. #include <LibWeb/Fetch/Request.h>
  8. namespace Web::Fetch::Infrastructure {
  9. // https://fetch.spec.whatwg.org/#determine-the-network-partition-key
  10. NetworkPartitionKey determine_the_network_partition_key(HTML::Environment const& environment)
  11. {
  12. // 1. Let topLevelOrigin be environment’s top-level origin.
  13. auto top_level_origin = environment.top_level_origin;
  14. // FIXME: 2. If topLevelOrigin is null, then set topLevelOrigin to environment’s top-level creation URL’s origin
  15. // This field is supposed to be nullable
  16. // 3. Assert: topLevelOrigin is an origin.
  17. // FIXME: 4. Let topLevelSite be the result of obtaining a site, given topLevelOrigin.
  18. // 5. Let secondKey be null or an implementation-defined value.
  19. void* second_key = nullptr;
  20. // 6. Return (topLevelSite, secondKey).
  21. return { top_level_origin, second_key };
  22. }
  23. // https://fetch.spec.whatwg.org/#request-determine-the-network-partition-key
  24. Optional<NetworkPartitionKey> determine_the_network_partition_key(Infrastructure::Request const& request)
  25. {
  26. // 1. If request’s reserved client is non-null, then return the result of determining the network partition key given request’s reserved client.
  27. if (auto reserved_client = request.reserved_client())
  28. return determine_the_network_partition_key(*reserved_client);
  29. // 2. If request’s client is non-null, then return the result of determining the network partition key given request’s client.
  30. if (auto client = request.client())
  31. return determine_the_network_partition_key(*client);
  32. return {};
  33. }
  34. }