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

Code before:
                        r.set_type(DOMResponseType::Opaqueredirect, CanGc::note());
                        r.set_final_url(url);
                    },
                },
            },
        }

        // Step 12.5. Resolve p with responseObject.
        promise.resolve_native(&self.response_object.root(), CanGc::note());
        self.fetch_promise = Some(TrustedPromise::new(promise));
    }

    fn process_response_chunk(&mut self, _: RequestId, chunk: Vec<u8>) {
        let response = self.response_object.root();
        response.stream_chunk(chunk, CanGc::note());
    }

    fn process_response_eof(
        self,
        _: RequestId,
        response: Result<(), NetworkError>,
        timing: ResourceFetchTiming,
    ) {
        let response_object = self.response_object.root();
        let _ac = enter_realm(&*response_object);
        if let Err(e) = response.clone() {
            if e == NetworkError::DecompressionError {
                response_object.error_stream(
                    Error::Type("Network error occurred".to_string()),
                    CanGc::note(),
                );
            }
        }
        response_object.finish(CanGc::note());
        // TODO
        // ... trailerObject is not supported in Servo yet.

        // navigation submission is handled in servoparser/mod.rs
        network_listener::submit_timing(&self, &response, &timing, CanGc::note());
    }

    fn process_csp_violations(&mut self, _request_id: RequestId, violations: Vec<Violation>) {
        let global = &self.resource_timing_global();
        global.report_csp_violations(violations, None, None);
    }
}

impl ResourceTimingListener for FetchContext {
    fn resource_timing_information(&self) -> (InitiatorType, ServoUrl) {
        (InitiatorType::Fetch, self.url.clone())
    }

Review comment (suggestion):
```suggestion
        if let Err(error) = response.clone() {
```

Code after:
                        r.set_type(DOMResponseType::Opaqueredirect, CanGc::note());
                        r.set_final_url(url);
                    },
                },
            },
        }

        // Step 12.5. Resolve p with responseObject.
        promise.resolve_native(&self.response_object.root(), CanGc::note());
        self.fetch_promise = Some(TrustedPromise::new(promise));
    }

    fn process_response_chunk(&mut self, _: RequestId, chunk: Vec<u8>) {
        let response = self.response_object.root();
        response.stream_chunk(chunk, CanGc::note());
    }

    fn process_response_eof(
        self,
        _: RequestId,
        response: Result<(), NetworkError>,
        timing: ResourceFetchTiming,
    ) {
        let response_object = self.response_object.root();
        let _ac = enter_realm(&*response_object);
        if let Err(ref error) = response {
            if *error == NetworkError::DecompressionError {
                response_object.error_stream(
                    Error::Type("Network error occurred".to_string()),
                    CanGc::note(),
                );
            }
        }
        response_object.finish(CanGc::note());
        // TODO
        // ... trailerObject is not supported in Servo yet.

        // navigation submission is handled in servoparser/mod.rs
        network_listener::submit_timing(&self, &response, &timing, CanGc::note());
    }

    fn process_csp_violations(&mut self, _request_id: RequestId, violations: Vec<Violation>) {
        let global = &self.resource_timing_global();
        global.report_csp_violations(violations, None, None);
    }
}

impl ResourceTimingListener for FetchContext {
    fn resource_timing_information(&self) -> (InitiatorType, ServoUrl) {
        (InitiatorType::Fetch, self.url.clone())
    }