CORSSettingAttribute.cpp 933 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Copyright (c) 2023, Srikavin Ramkumar <me@srikavin.me>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/CORSSettingAttribute.h>
  7. namespace Web::HTML {
  8. // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes
  9. CORSSettingAttribute cors_setting_attribute_from_keyword(Optional<String> const& keyword)
  10. {
  11. if (!keyword.has_value()) {
  12. // its missing value default is the No CORS state
  13. return CORSSettingAttribute::NoCORS;
  14. }
  15. if (keyword->is_empty() || keyword->bytes_as_string_view().equals_ignoring_ascii_case("anonymous"sv)) {
  16. return CORSSettingAttribute::Anonymous;
  17. }
  18. if (keyword->bytes_as_string_view().equals_ignoring_ascii_case("use-credentials"sv)) {
  19. return CORSSettingAttribute::UseCredentials;
  20. }
  21. // The attribute's invalid value default is the Anonymous state
  22. return CORSSettingAttribute::Anonymous;
  23. }
  24. }