Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trailers methods #176

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pin_project_lite::pin_project! {
ext: Extensions,
trailers_sender: Option<sync::Sender<Trailers>>,
trailers_receiver: Option<sync::Receiver<Trailers>>,
has_trailers: bool,
}
}

Expand All @@ -63,6 +64,7 @@ impl Request {
local_addr: None,
trailers_receiver: Some(trailers_receiver),
trailers_sender: Some(trailers_sender),
has_trailers: false,
}
}

Expand Down Expand Up @@ -542,6 +544,7 @@ impl Request {

/// Sends trailers to the a receiver.
pub fn send_trailers(&mut self) -> trailers::Sender {
self.has_trailers = true;
let sender = self
.trailers_sender
.take()
Expand All @@ -550,14 +553,19 @@ impl Request {
}

/// Receive trailers from a sender.
pub async fn recv_trailers(&mut self) -> trailers::Receiver {
pub fn recv_trailers(&mut self) -> trailers::Receiver {
let receiver = self
.trailers_receiver
.take()
.expect("Trailers receiver can only be constructed once");
trailers::Receiver::new(receiver)
}

/// Returns `true` if sending trailers is in progress.
pub fn has_trailers(&self) -> bool {
self.has_trailers
}

/// An iterator visiting all header pairs in arbitrary order.
pub fn iter(&self) -> headers::Iter<'_> {
self.headers.iter()
Expand Down Expand Up @@ -873,6 +881,7 @@ impl Clone for Request {
ext: Extensions::new(),
peer_addr: self.peer_addr.clone(),
local_addr: self.local_addr.clone(),
has_trailers: false,
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pin_project_lite::pin_project! {
status: StatusCode,
headers: Headers,
version: Option<Version>,
has_trailers: bool,
trailers_sender: Option<sync::Sender<Trailers>>,
trailers_receiver: Option<sync::Receiver<Trailers>>,
#[pin]
Expand Down Expand Up @@ -75,6 +76,7 @@ pin_project_lite::pin_project! {
version: Option<Version>,
trailers_sender: Option<sync::Sender<Trailers>>,
trailers_receiver: Option<sync::Receiver<Trailers>>,
has_trailers: bool,
upgrade_sender: Option<sync::Sender<upgrade::Connection>>,
upgrade_receiver: Option<sync::Receiver<upgrade::Connection>>,
has_upgrade: bool,
Expand Down Expand Up @@ -105,6 +107,7 @@ impl Response {
body: Body::empty(),
trailers_sender: Some(trailers_sender),
trailers_receiver: Some(trailers_receiver),
has_trailers: false,
ext: Extensions::new(),
peer_addr: None,
local_addr: None,
Expand All @@ -130,6 +133,7 @@ impl Response {
body: Body::empty(),
trailers_sender: Some(trailers_sender),
trailers_receiver: Some(trailers_receiver),
has_trailers: false,
upgrade_sender: Some(upgrade_sender),
upgrade_receiver: Some(upgrade_receiver),
has_upgrade: false,
Expand Down Expand Up @@ -536,6 +540,7 @@ impl Response {

/// Sends trailers to the a receiver.
pub fn send_trailers(&mut self) -> trailers::Sender {
self.has_trailers = true;
let sender = self
.trailers_sender
.take()
Expand All @@ -544,14 +549,19 @@ impl Response {
}

/// Receive trailers from a sender.
pub async fn recv_trailers(&mut self) -> trailers::Receiver {
pub fn recv_trailers(&mut self) -> trailers::Receiver {
let receiver = self
.trailers_receiver
.take()
.expect("Trailers receiver can only be constructed once");
trailers::Receiver::new(receiver)
}

/// Returns `true` if sending trailers is in progress.
pub fn has_trailers(&self) -> bool {
self.has_trailers
}

/// Sends an upgrade connection to the a receiver.
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
Expand Down Expand Up @@ -640,6 +650,7 @@ impl Clone for Response {
version: self.version.clone(),
trailers_sender: self.trailers_sender.clone(),
trailers_receiver: self.trailers_receiver.clone(),
has_trailers: false,
#[cfg(feature = "unstable")]
upgrade_sender: self.upgrade_sender.clone(),
#[cfg(feature = "unstable")]
Expand Down