Skip to content

Commit 51101f3

Browse files
committed
Implement Clone for Request and Response, resolving the body to
`Body::empty()` and removing all extensions (as they are not clonable).
1 parent 756a0e0 commit 51101f3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/headers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use to_header_values::ToHeaderValues;
2525
pub use values::Values;
2626

2727
/// A collection of HTTP Headers.
28-
#[derive(Debug)]
28+
#[derive(Debug, Clone)]
2929
pub struct Headers {
3030
pub(crate) headers: HashMap<HeaderName, Vec<HeaderValue>>,
3131
}

src/request.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,22 @@ impl Request {
486486
}
487487
}
488488

489+
impl Clone for Request {
490+
/// Clone the request, resolving the body to `Body::empty()` and removing extensions.
491+
fn clone(&self) -> Self {
492+
Request {
493+
method: self.method.clone(),
494+
url: self.url.clone(),
495+
headers: self.headers.clone(),
496+
version: self.version.clone(),
497+
sender: self.sender.clone(),
498+
receiver: self.receiver.clone(),
499+
body: Body::empty(),
500+
local: TypeMap::new(),
501+
}
502+
}
503+
}
504+
489505
impl Read for Request {
490506
#[allow(missing_doc_code_examples)]
491507
fn poll_read(

src/response.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,21 @@ impl Response {
451451
}
452452
}
453453

454+
impl Clone for Response {
455+
/// Clone the response, resolving the body to `Body::empty()` and removing extensions.
456+
fn clone(&self) -> Self {
457+
Self {
458+
status: self.status.clone(),
459+
headers: self.headers.clone(),
460+
version: self.version.clone(),
461+
sender: self.sender.clone(),
462+
receiver: self.receiver.clone(),
463+
body: Body::empty(),
464+
local: TypeMap::new(),
465+
}
466+
}
467+
}
468+
454469
impl Read for Response {
455470
#[allow(missing_doc_code_examples)]
456471
fn poll_read(

0 commit comments

Comments
 (0)