URL.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include <LibWeb/MimeSniff/MimeType.h>
  15. namespace Web::Fetch::Infrastructure {
  16. // https://fetch.spec.whatwg.org/#local-scheme
  17. // A local scheme is "about", "blob", or "data".
  18. inline constexpr Array LOCAL_SCHEMES = {
  19. "about"sv, "blob"sv, "data"sv
  20. };
  21. // https://fetch.spec.whatwg.org/#http-scheme
  22. // An HTTP(S) scheme is "http" or "https".
  23. inline constexpr Array HTTP_SCHEMES = {
  24. "http"sv, "https"sv
  25. };
  26. // https://fetch.spec.whatwg.org/#fetch-scheme
  27. // A fetch scheme is "about", "blob", "data", "file", or an HTTP(S) scheme.
  28. inline constexpr Array FETCH_SCHEMES = {
  29. "about"sv, "blob"sv, "data"sv, "file"sv, "http"sv, "https"sv,
  30. // AD-HOC: Internal fetch schemes:
  31. "resource"sv
  32. };
  33. // https://fetch.spec.whatwg.org/#data-url-struct
  34. struct DataURL {
  35. MimeSniff::MimeType mime_type;
  36. ByteBuffer body;
  37. };
  38. [[nodiscard]] bool is_local_url(URL::URL const&);
  39. [[nodiscard]] bool is_fetch_scheme(StringView);
  40. [[nodiscard]] bool is_http_or_https_scheme(StringView);
  41. ErrorOr<DataURL> process_data_url(URL::URL const&);
  42. }