Skip to content

Commit

Permalink
LibWeb/Fetch: Append the Fetch metadata headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks authored and awesomekling committed May 1, 2024
1 parent e52f444 commit f5799f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
Expand Up @@ -1355,7 +1355,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
// 12. Append a request `Origin` header for httpRequest.
http_request->add_origin_header();

// FIXME: 13. Append the Fetch metadata headers for httpRequest.
// 13. Append the Fetch metadata headers for httpRequest.
append_fetch_metadata_headers_for_request(*http_request);

// 14. If httpRequest’s header list does not contain `User-Agent`, then user agents should append
// (`User-Agent`, default `User-Agent` value) to httpRequest’s header list.
Expand Down Expand Up @@ -2103,4 +2104,24 @@ void set_sec_fetch_user_header(Infrastructure::Request& request)
request.header_list()->append(move(header));
}

// https://w3c.github.io/webappsec-fetch-metadata/#abstract-opdef-append-the-fetch-metadata-headers-for-a-request
void append_fetch_metadata_headers_for_request(Infrastructure::Request& request)
{
// 1. If r’s url is not an potentially trustworthy URL, return.
if (SecureContexts::is_url_potentially_trustworthy(request.url()) != SecureContexts::Trustworthiness::PotentiallyTrustworthy)
return;

// 2. Set the Sec-Fetch-Dest header for r.
set_sec_fetch_dest_header(request);

// 3. Set the Sec-Fetch-Mode header for r.
set_sec_fetch_mode_header(request);

// 4. Set the Sec-Fetch-Site header for r.
set_sec_fetch_site_header(request);

// 5. Set the Sec-Fetch-User header for r.
set_sec_fetch_user_header(request);
}

}
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.h
Expand Up @@ -43,4 +43,5 @@ void set_sec_fetch_dest_header(Infrastructure::Request&);
void set_sec_fetch_mode_header(Infrastructure::Request&);
void set_sec_fetch_site_header(Infrastructure::Request&);
void set_sec_fetch_user_header(Infrastructure::Request&);
void append_fetch_metadata_headers_for_request(Infrastructure::Request&);
}

0 comments on commit f5799f7

Please sign in to comment.