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

Code before:
        .update_awaiting_consumers(request, &response)
        .await;

    // Steps 25-27.
    // TODO: remove this line when only asynchronous fetches are used
    response
}

async fn wait_for_response(
    request: &Request,
    response: &mut Response,
    target: Target<'_>,
    done_chan: &mut DoneChannel,
    context: &FetchContext,
) {
    if let Some(ref mut ch) = *done_chan {
        let mut devtools_body = context.devtools_chan.as_ref().map(|_| Vec::new());
        loop {
            match ch.1.recv().await {
                Some(Data::Payload(vec)) => {
                    if let Some(body) = devtools_body.as_mut() {
                        body.extend(&vec);
                    }
                    target.process_response_chunk(request, vec);
                },
                Some(Data::Error(e)) => {
                    response.set_network_error(NetworkError::DecompressionError);
                    break;
                },
                Some(Data::Done) => {
                    send_response_to_devtools(request, context, response, devtools_body);
                    break;
                },
                Some(Data::Cancelled) => {
                    response.aborted.store(true, Ordering::Release);
                    break;
                },
                _ => {
                    panic!("fetch worker should always send Done before terminating");
                },
            }
        }
    } else {
        match *response.actual_response().body.lock() {
            ResponseBody::Done(ref vec) if !vec.is_empty() => {
                // in case there was no channel to wait for, the body was
                // obtained synchronously via scheme_fetch for data/file/about/etc
                // We should still send the body across as a chunk
                target.process_response_chunk(request, vec.clone());
                if context.devtools_chan.is_some() {
                    // Now that we've replayed the entire cached body,

Review comment (suggestion):
```suggestion
                Some(Data::Error(..)) => {
```

Code after:
        .update_awaiting_consumers(request, &response)
        .await;

    // Steps 25-27.
    // TODO: remove this line when only asynchronous fetches are used
    response
}

async fn wait_for_response(
    request: &Request,
    response: &mut Response,
    target: Target<'_>,
    done_chan: &mut DoneChannel,
    context: &FetchContext,
) {
    if let Some(ref mut ch) = *done_chan {
        let mut devtools_body = context.devtools_chan.as_ref().map(|_| Vec::new());
        loop {
            match ch.1.recv().await {
                Some(Data::Payload(vec)) => {
                    if let Some(body) = devtools_body.as_mut() {
                        body.extend(&vec);
                    }
                    target.process_response_chunk(request, vec);
                },
                Some(Data::Error(network_error)) => {
                    response.set_network_error(network_error);
                    break;
                },
                Some(Data::Done) => {
                    send_response_to_devtools(request, context, response, devtools_body);
                    break;
                },
                Some(Data::Cancelled) => {
                    response.aborted.store(true, Ordering::Release);
                    break;
                },
                _ => {
                    panic!("fetch worker should always send Done before terminating");
                },
            }
        }
    } else {
        match *response.actual_response().body.lock() {
            ResponseBody::Done(ref vec) if !vec.is_empty() => {
                // in case there was no channel to wait for, the body was
                // obtained synchronously via scheme_fetch for data/file/about/etc
                // We should still send the body across as a chunk
                target.process_response_chunk(request, vec.clone());
                if context.devtools_chan.is_some() {
                    // Now that we've replayed the entire cached body,