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

Code before:
                let mut body = res_body.lock();
                let completed_body = match *body {
                    ResponseBody::Receiving(ref mut body) => std::mem::take(body),
                    _ => vec![],
                };
                let devtools_response_body = completed_body.clone();
                *body = ResponseBody::Done(completed_body);
                send_response_values_to_devtools(
                    Some(headers),
                    status,
                    Some(devtools_response_body),
                    CacheState::None,
                    &devtools_request,
                    devtools_chan,
                );
                timing_ptr2
                    .lock()
                    .set_attribute(ResourceAttribute::ResponseEnd);
                let _ = done_sender2.send(Data::Done);
                future::ready(Ok(()))
            })
            .map_err(move |e| {
                info!("\x1b[33mError streaming response body: {:?}\x1b[0m", e);
                match e.kind() {
                    std::io::ErrorKind::InvalidData => {
                        log::info!("\x1b[33mContent decompression error for {:?}\x1b[0m", url2);
                        let _ = done_sender3
                            .send(Data::Error(String::from("Content decompression error")));
                        let mut body = res_body2.lock();
                        response.termination_reason = Some(TerminationReason::Fatal);

                        *body = ResponseBody::Done(vec![]);
                    },

                    _ => {},
                }
                debug!("\x1b[42mfinished response for {:?}\x1b[0m", url2);
                let mut body = res_body2.lock();
                let completed_body = match *body {
                    ResponseBody::Receiving(ref mut body) => std::mem::take(body),
                    _ => vec![],
                };
                *body = ResponseBody::Done(completed_body);
                timing_ptr3
                    .lock()
                    .set_attribute(ResourceAttribute::ResponseEnd);
                let _ = done_sender3.send(Data::Done);
            }),
    );

    // TODO these substeps aren't possible yet

Review comment (security):
Is this a termainal escape code? Let's remove that. It's not necessary in logging output and it isn't guaranteed that the output is a terminal.

```suggestion
                        log::info!("Content decompression error for {error:?}\x1b[0m", url2);
```

Code after:
                let mut body = res_body.lock();
                let completed_body = match *body {
                    ResponseBody::Receiving(ref mut body) => std::mem::take(body),
                    _ => vec![],
                };
                let devtools_response_body = completed_body.clone();
                *body = ResponseBody::Done(completed_body);
                send_response_values_to_devtools(
                    Some(headers),
                    status,
                    Some(devtools_response_body),
                    CacheState::None,
                    &devtools_request,
                    devtools_chan,
                );
                timing_ptr2
                    .lock()
                    .set_attribute(ResourceAttribute::ResponseEnd);
                let _ = done_sender2.send(Data::Done);
                future::ready(Ok(()))
            })
            .map_err(move |error| {
                if let std::io::ErrorKind::InvalidData = error.kind() {
                    debug!("Content decompression error for {:?}", url2);
                    let _ = done_sender3.send(Data::Error(NetworkError::DecompressionError));
                    let mut body = res_body2.lock();
                    response.termination_reason = Some(TerminationReason::Fatal);

                    *body = ResponseBody::Done(vec![]);
                }
                debug!("finished response for {:?}", url2);
                let mut body = res_body2.lock();
                let completed_body = match *body {
                    ResponseBody::Receiving(ref mut body) => std::mem::take(body),
                    _ => vec![],
                };
                *body = ResponseBody::Done(completed_body);
                timing_ptr3
                    .lock()
                    .set_attribute(ResourceAttribute::ResponseEnd);
                let _ = done_sender3.send(Data::Done);
            }),
    );

    // TODO these substeps aren't possible yet
    // Substep 1

    // Substep 2

    response.https_state = match url.scheme() {
        "https" => HttpsState::Modern,