URL.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  3. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Array.h>
  9. #include <AK/ByteBuffer.h>
  10. #include <AK/Error.h>
  11. #include <AK/String.h>
  12. #include <AK/StringView.h>
  13. #include <LibURL/Forward.h>
  14. namespace Web::Fetch::Infrastructure {
  15. // https://fetch.spec.whatwg.org/#local-scheme
  16. // A local scheme is "about", "blob", or "data".
  17. inline constexpr Array LOCAL_SCHEMES = {
  18. "about"sv, "blob"sv, "data"sv
  19. };
  20. // https://fetch.spec.whatwg.org/#http-scheme
  21. // An HTTP(S) scheme is "http" or "https".
  22. inline constexpr Array HTTP_SCHEMES = {
  23. "http"sv, "https"sv
  24. };
  25. // https://fetch.spec.whatwg.org/#fetch-scheme
  26. // A fetch scheme is "about", "blob", "data", "file", or an HTTP(S) scheme.
  27. inline constexpr Array FETCH_SCHEMES = {
  28. "about"sv, "blob"sv, "data"sv, "file"sv, "http"sv, "https"sv,
  29. // AD-HOC: Internal fetch schemes:
  30. "resource"sv
  31. };
  32. // https://fetch.spec.whatwg.org/#data-url-struct
  33. struct DataURL {
  34. String mime_type;
  35. ByteBuffer body;
  36. };
  37. [[nodiscard]] bool is_local_url(URL::URL const&);
  38. [[nodiscard]] bool is_fetch_scheme(StringView);
  39. [[nodiscard]] bool is_http_or_https_scheme(StringView);
  40. ErrorOr<DataURL> process_data_url(URL::URL const&);
  41. }