mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Fetch cancellation: Listen for cancellation and prematurely abort if cancelled
This commit is contained in:
parent
6dd7af2bda
commit
7249fd6bd8
1 changed files with 6 additions and 0 deletions
|
@ -1087,6 +1087,7 @@ fn http_network_fetch(request: &Request,
|
||||||
let devtools_sender = context.devtools_chan.clone();
|
let devtools_sender = context.devtools_chan.clone();
|
||||||
let meta_status = meta.status.clone();
|
let meta_status = meta.status.clone();
|
||||||
let meta_headers = meta.headers.clone();
|
let meta_headers = meta.headers.clone();
|
||||||
|
let cancellation_listener = context.cancellation_listener.clone();
|
||||||
thread::Builder::new().name(format!("fetch worker thread")).spawn(move || {
|
thread::Builder::new().name(format!("fetch worker thread")).spawn(move || {
|
||||||
match StreamedResponse::from_http_response(res) {
|
match StreamedResponse::from_http_response(res) {
|
||||||
Ok(mut res) => {
|
Ok(mut res) => {
|
||||||
|
@ -1109,6 +1110,11 @@ fn http_network_fetch(request: &Request,
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
if cancellation_listener.lock().unwrap().cancelled() {
|
||||||
|
*res_body.lock().unwrap() = ResponseBody::Done(vec![]);
|
||||||
|
let _ = done_sender.send(Data::Done);
|
||||||
|
return;
|
||||||
|
}
|
||||||
match read_block(&mut res) {
|
match read_block(&mut res) {
|
||||||
Ok(Data::Payload(chunk)) => {
|
Ok(Data::Payload(chunk)) => {
|
||||||
if let ResponseBody::Receiving(ref mut body) = *res_body.lock().unwrap() {
|
if let ResponseBody::Receiving(ref mut body) = *res_body.lock().unwrap() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue