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

chore(interceptor): Remove unnecessary BoxBody from interceptor #1987

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
18 changes: 7 additions & 11 deletions tonic/src/service/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
//!
//! See [`Interceptor`] for more details.

use crate::{
body::{boxed, BoxBody},
request::SanitizeHeaders,
Status,
};
use crate::{request::SanitizeHeaders, Status};
use bytes::Bytes;
use pin_project::pin_project;
use std::{
Expand Down Expand Up @@ -128,7 +124,7 @@ where
ResBody: http_body::Body<Data = bytes::Bytes> + Send + 'static,
ResBody::Error: Into<crate::Error>,
{
type Response = http::Response<BoxBody>;
type Response = http::Response<ResBody>;
type Error = S::Error;
type Future = ResponseFuture<S::Future>;

Expand Down Expand Up @@ -208,13 +204,11 @@ where
B: Default + http_body::Body<Data = Bytes> + Send + 'static,
B::Error: Into<crate::Error>,
{
type Output = Result<http::Response<BoxBody>, E>;
type Output = Result<http::Response<B>, E>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.project().kind.project() {
KindProj::Future(future) => future
.poll(cx)
.map(|result| result.map(|res| res.map(boxed))),
KindProj::Future(future) => future.poll(cx),
KindProj::Status(status) => {
let response = status.take().unwrap().into_http();
Poll::Ready(Ok(response))
Expand All @@ -225,11 +219,13 @@ where

#[cfg(test)]
mod tests {
use super::*;
use http_body::Frame;
use http_body_util::Empty;
use tower::ServiceExt;

use super::*;
use crate::body::BoxBody;

#[derive(Debug, Default)]
struct TestBody;

Expand Down