Repository: servo/servo
File: components/net/fetch/methods.rs (Rust)

Code before:
            None => Response::network_error(NetworkError::Internal("Unexpected scheme".into())),
        },
    }
}

fn is_null_body_status(status: &HttpStatus) -> bool {
    matches!(
        status.try_code(),
        Some(StatusCode::SWITCHING_PROTOCOLS) |
            Some(StatusCode::NO_CONTENT) |
            Some(StatusCode::RESET_CONTENT) |
            Some(StatusCode::NOT_MODIFIED)
    )
}

fn should_response_be_blocked_by_csp(
    request: &Request,
    response: &Response,
    target: Target<'_>,
) -> bool {
    if response.is_network_error() {
        return false;
    }
    let policy_container = match &request.policy_container {
        RequestPolicyContainer::Client => return false,
        RequestPolicyContainer::PolicyContainer(container) => container.to_owned(),
    };
    let Some(csp_list) = policy_container.csp_list else {
        return false;
    };
    let origin = match &request.origin {
        Origin::Client => return false,
        Origin::Origin(origin) => origin,
    };

    let csp_request = convert_request_to_csp_request(request, origin);
    let csp_response = csp::Response {
        url: response
            .actual_response()
            .url()
            .cloned()
            .expect("response must have a url")
            .into_url(),
        redirect_count: request.redirect_count,
    };

    let (result, violations) =
        csp_list.should_response_to_request_be_blocked(&csp_request, &csp_response);
    if !violations.is_empty() {
        target.process_csp_violations(request, violations);
    }

Review comment (suggestion):
clone on policy_container seems unnecessary?

```suggestion
        RequestPolicyContainer::PolicyContainer(container) => container,
```

Code after:
    match scheme {
        "about" if url.path() == "blank" => create_blank_reply(url, request.timing_type()),
        "about" if url.path() == "memory" => create_about_memory(url, request.timing_type()),

        "chrome" if url.path() == "allowcert" => {
            if let Err(error) = handle_allowcert_request(request, context) {
                warn!("Could not handle allowcert request: {error}");
            }
            create_blank_reply(url, request.timing_type())
        },

        "http" | "https" => {
            http_fetch(
                fetch_params,
                cache,
                false,
                false,
                false,
                target,
                done_chan,
                context,
            )
            .await
        },

        _ => match context.protocols.get(scheme) {
            Some(handler) => handler.load(request, done_chan, context).await,
            None => Response::network_error(NetworkError::Internal("Unexpected scheme".into())),
        },
    }
}

fn is_null_body_status(status: &HttpStatus) -> bool {
    matches!(
        status.try_code(),
        Some(StatusCode::SWITCHING_PROTOCOLS) |
            Some(StatusCode::NO_CONTENT) |
            Some(StatusCode::RESET_CONTENT) |
            Some(StatusCode::NOT_MODIFIED)
    )
}

/// <https://fetch.spec.whatwg.org/#should-response-to-request-be-blocked-due-to-nosniff?>
pub fn should_be_blocked_due_to_nosniff(
    destination: Destination,
    response_headers: &HeaderMap,
) -> bool {
    // Step 1
    if !determine_nosniff(response_headers) {
        return false;
    }