Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / cors_setting_attribute.lucb

#==============================================================================================
#
#   cors_setting_attribute - HTML::CORSSettingAttribute: the CORS settings attribute states
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/CORSSettingAttribute.cpp (lines 1-46): a crossorigin attribute's
#       state from its keyword, and the state's credentials mode.
#
#==============================================================================================

## Ported from CORSSettingAttribute.cpp:12 Web::HTML::cors_setting_attribute_from_keyword.
# https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attributes
pub func html_cors_setting_attribute_from_keyword(keyword: ak.String?) -> HtmlCorsSettingAttribute:
    # If the keyword is missing: its missing value default is the No CORS state
    let value = keyword else return HtmlCorsSettingAttribute.no_cors
    let view = ak.string_bytes_as_string_view(&value)
    if ak.string_view_equals_ignoring_ascii_case(&view, ak.sv("use-credentials")):
        return HtmlCorsSettingAttribute.use_credentials

    # The attribute's invalid value default is the Anonymous state
    return HtmlCorsSettingAttribute.anonymous

## Ported from CORSSettingAttribute.cpp:27 Web::HTML::cors_settings_attribute_credentials_mode.
# https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attribute-credentials-mode
pub func html_cors_settings_attribute_credentials_mode(attribute: HtmlCorsSettingAttribute) -> FetchRequestCredentialsMode:
    match attribute:
        # -> No CORS
        # -> Anonymous
        .no_cors, .anonymous:
            # "same-origin"
            return FetchRequestCredentialsMode.same_origin

        # -> Use Credentials
        .use_credentials:
            # "include"
            return FetchRequestCredentialsMode.include
        _:
            trap("VERIFY_NOT_REACHED")