mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
clear extensions before reclaiming HttpRequests in their pool (#1063)
Issue #1062
This commit is contained in:
parent
98bf8ab098
commit
616981ecf9
@ -259,6 +259,7 @@ impl Drop for HttpRequest {
|
|||||||
if Rc::strong_count(&self.0) == 1 {
|
if Rc::strong_count(&self.0) == 1 {
|
||||||
let v = &mut self.0.pool.0.borrow_mut();
|
let v = &mut self.0.pool.0.borrow_mut();
|
||||||
if v.len() < 128 {
|
if v.len() < 128 {
|
||||||
|
self.extensions_mut().clear();
|
||||||
v.push(self.0.clone());
|
v.push(self.0.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -494,4 +495,36 @@ mod tests {
|
|||||||
let resp = call_service(&mut srv, req);
|
let resp = call_service(&mut srv, req);
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_extensions_dropped() {
|
||||||
|
struct Tracker {
|
||||||
|
pub dropped: bool,
|
||||||
|
}
|
||||||
|
struct Foo {
|
||||||
|
tracker: Rc<RefCell<Tracker>>,
|
||||||
|
}
|
||||||
|
impl Drop for Foo {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.tracker.borrow_mut().dropped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let tracker = Rc::new(RefCell::new(Tracker { dropped: false }));
|
||||||
|
{
|
||||||
|
let tracker2 = Rc::clone(&tracker);
|
||||||
|
let mut srv = init_service(App::new().data(10u32).service(
|
||||||
|
web::resource("/").to(move |req: HttpRequest| {
|
||||||
|
req.extensions_mut().insert(Foo { tracker: Rc::clone(&tracker2) });
|
||||||
|
HttpResponse::Ok()
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
let req = TestRequest::default().to_request();
|
||||||
|
let resp = call_service(&mut srv, req);
|
||||||
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert!(tracker.borrow().dropped);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user