mirror of
https://github.com/servo/servo.git
synced 2025-09-27 23:30:08 +01:00
Add resource header for mime sniffing (#39167)
The concept of a "resource header" is not well specced, since it is unclear what a "resource" is. That said, it most closely matches a "response" as part of the navigation params. With this change, we now delay loading the document until either two things happen: 1. We reached the end of the file 2. We processed 1445 bytes (as defined by spec) We initially store bytes in the resource header and then after loading parse the stored bytes. Any subsequent loading will process as before. Part of #14024 Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This commit is contained in:
parent
e3de39893f
commit
a672ffb850
7 changed files with 133 additions and 83 deletions
|
@ -137,6 +137,19 @@ pub enum ReferrerPolicy {
|
|||
StrictOriginWhenCrossOrigin,
|
||||
}
|
||||
|
||||
impl ReferrerPolicy {
|
||||
/// <https://w3c.github.io/webappsec-referrer-policy/#parse-referrer-policy-from-header>
|
||||
pub fn parse_header_for_response(headers: &Option<Serde<HeaderMap>>) -> Self {
|
||||
// Step 4. Return policy.
|
||||
headers
|
||||
.as_ref()
|
||||
// Step 1. Let policy-tokens be the result of extracting header list values given `Referrer-Policy` and response’s header list.
|
||||
.and_then(|headers| headers.typed_get::<ReferrerPolicyHeader>())
|
||||
// Step 2-3.
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ReferrerPolicy {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let string = match self {
|
||||
|
@ -154,8 +167,11 @@ impl Display for ReferrerPolicy {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://w3c.github.io/webappsec-referrer-policy/#parse-referrer-policy-from-header>
|
||||
impl From<Option<ReferrerPolicyHeader>> for ReferrerPolicy {
|
||||
fn from(header: Option<ReferrerPolicyHeader>) -> Self {
|
||||
// Step 2. Let policy be the empty string.
|
||||
// Step 3. For each token in policy-tokens, if token is a referrer policy and token is not the empty string, then set policy to token.
|
||||
header.map_or(ReferrerPolicy::EmptyString, |policy| match policy {
|
||||
ReferrerPolicyHeader::NO_REFERRER => ReferrerPolicy::NoReferrer,
|
||||
ReferrerPolicyHeader::NO_REFERRER_WHEN_DOWNGRADE => {
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct PolicyContainer {
|
|||
/// <https://html.spec.whatwg.org/multipage/#policy-container-csp-list>
|
||||
pub csp_list: Option<CspList>,
|
||||
/// <https://html.spec.whatwg.org/multipage/#policy-container-referrer-policy>
|
||||
referrer_policy: ReferrerPolicy,
|
||||
pub referrer_policy: ReferrerPolicy,
|
||||
// https://html.spec.whatwg.org/multipage/#policy-container-embedder-policy
|
||||
// TODO: Embedder Policy
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue