Skip to content

Commit

Permalink
Add trillium::Conn::response_body() to borrow the response body
Browse files Browse the repository at this point in the history
trillium_http::Conn supports returning a borrow of the response body,
but trillium:Conn doesn't have a corresponding method.

This is useful for examining a response body non-destructively without
having to take it and re-set it afterwards.
  • Loading branch information
joshtriplett authored and jbr committed Oct 16, 2023
1 parent c0025d8 commit bc28015
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions trillium/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ impl Conn {
self.inner.take_response_body()
}

/**
Borrows the response body from the `Conn`
```
use trillium_testing::prelude::*;
let mut conn = get("/").on(&());
conn.set_body("hello");
let body = conn.response_body().unwrap();
assert_eq!(body.len(), Some(5));
assert!(body.is_static());
assert_eq!(body.static_bytes(), Some(&b"hello"[..]));
```
*/
pub fn response_body(&self) -> Option<&Body> {
self.inner.response_body()
}

/**
Attempts to retrieve a &T from the state set
Expand Down

0 comments on commit bc28015

Please sign in to comment.