feat(net): make passive request/response callbacks detachable (#416)
on_request/on_response stored callbacks in append-only Vecs with no way to remove one, so a crawler that installed a response-body capture hook for one phase could never detach it: it fired for the shared client's whole lifetime, re-registering across navigations piled up duplicates, and (because the client is shared per context) it saw sibling pages' requests too. Tag each callback with a stable id. on_request/on_response now return the id and off_request/off_response (remove_on_request/remove_on_response on the client) detach a specific one. Storage is Vec<(u64, Callback)>; all fire sites destructure the tuple. Closes #408.
This commit is contained in:
1 parent
d0b6fc4ffd
commit
99ece0e12d
5 files changed
+147
-23
No files matched your search
@@ -792,7 +792,7 @@ async fn op_fetch_url(
|
||||
headers: custom_headers.clone(),
|
||||
resource_type: ResourceType::Fetch,
|
||||
};
|
||||
for cb in cbs.iter() {
|
||||
for (_, cb) in cbs.iter() {
|
||||
cb(&info);
|
||||
}
|
||||
}
|
||||
@@ -1038,7 +1038,7 @@ async fn op_fetch_url(
|
||||
headers: resp_headers.clone(),
|
||||
resource_type: ResourceType::Fetch,
|
||||
};
|
||||
for cb in cbs.iter() {
|
||||
for (_, cb) in cbs.iter() {
|
||||
cb(&info, &resp);
|
||||
}
|
||||
}
|
||||
@@ -1231,7 +1231,7 @@ async fn stealth_fetch_all(
|
||||
headers: resp_headers.clone(),
|
||||
resource_type: ResourceType::Fetch,
|
||||
};
|
||||
for cb in cbs.iter() {
|
||||
for (_, cb) in cbs.iter() {
|
||||
cb(&info, &resp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user