mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 01:47:36 +00:00
LibWeb: Honor User-Agent spoofing in Fetch headers
This makes spoofing consistent between legacy ResourceLoader loads, Fetch loads, and the JavaScript `navigator` APIs.
This commit is contained in:
parent
a30d263522
commit
89da988da1
3 changed files with 4 additions and 4 deletions
|
@ -1354,7 +1354,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
|
||||||
if (!http_request->header_list()->contains("User-Agent"sv.bytes())) {
|
if (!http_request->header_list()->contains("User-Agent"sv.bytes())) {
|
||||||
auto header = Infrastructure::Header {
|
auto header = Infrastructure::Header {
|
||||||
.name = MUST(ByteBuffer::copy("User-Agent"sv.bytes())),
|
.name = MUST(ByteBuffer::copy("User-Agent"sv.bytes())),
|
||||||
.value = TRY_OR_THROW_OOM(vm, Infrastructure::default_user_agent_value()),
|
.value = Infrastructure::default_user_agent_value(),
|
||||||
};
|
};
|
||||||
TRY_OR_THROW_OOM(vm, http_request->header_list()->append(move(header)));
|
TRY_OR_THROW_OOM(vm, http_request->header_list()->append(move(header)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -882,10 +882,10 @@ Optional<RangeHeaderValue> parse_single_range_header_value(ReadonlyBytes value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://fetch.spec.whatwg.org/#default-user-agent-value
|
// https://fetch.spec.whatwg.org/#default-user-agent-value
|
||||||
ErrorOr<ByteBuffer> default_user_agent_value()
|
ByteBuffer default_user_agent_value()
|
||||||
{
|
{
|
||||||
// A default `User-Agent` value is an implementation-defined header value for the `User-Agent` header.
|
// A default `User-Agent` value is an implementation-defined header value for the `User-Agent` header.
|
||||||
return ByteBuffer::copy(default_user_agent.bytes());
|
return MUST(ByteBuffer::copy(ResourceLoader::the().user_agent().bytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,6 @@ struct ExtractHeaderParseFailure {
|
||||||
[[nodiscard]] ErrorOr<Optional<Vector<ByteBuffer>>> extract_header_values(Header const&);
|
[[nodiscard]] ErrorOr<Optional<Vector<ByteBuffer>>> extract_header_values(Header const&);
|
||||||
[[nodiscard]] ErrorOr<Variant<Vector<ByteBuffer>, ExtractHeaderParseFailure, Empty>> extract_header_list_values(ReadonlyBytes, HeaderList const&);
|
[[nodiscard]] ErrorOr<Variant<Vector<ByteBuffer>, ExtractHeaderParseFailure, Empty>> extract_header_list_values(ReadonlyBytes, HeaderList const&);
|
||||||
[[nodiscard]] Optional<RangeHeaderValue> parse_single_range_header_value(ReadonlyBytes);
|
[[nodiscard]] Optional<RangeHeaderValue> parse_single_range_header_value(ReadonlyBytes);
|
||||||
[[nodiscard]] ErrorOr<ByteBuffer> default_user_agent_value();
|
[[nodiscard]] ByteBuffer default_user_agent_value();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue