Skip to content

Commit

Permalink
chore!: Remove deprecated api (hyperium#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Nov 23, 2024
1 parent c70ba3f commit f4a879d
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 210 deletions.
6 changes: 3 additions & 3 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ path = "src/codec_buffers/client.rs"


[features]
gcp = ["dep:prost-types", "tonic/tls"]
gcp = ["dep:prost-types", "tonic/tls-ring"]
routeguide = ["dep:async-stream", "tokio-stream", "dep:rand", "dep:serde", "dep:serde_json"]
reflection = ["dep:tonic-reflection"]
autoreload = ["tokio-stream/net", "dep:listenfd"]
Expand All @@ -263,9 +263,9 @@ mock = ["tokio-stream", "dep:tower", "dep:hyper-util"]
tower = ["dep:tower", "dep:http"]
json-codec = ["dep:serde", "dep:serde_json", "dep:bytes"]
compression = ["tonic/gzip"]
tls = ["tonic/tls"]
tls = ["tonic/tls-ring"]
tls-rustls = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:hyper-rustls", "dep:tower", "tower-http/util", "tower-http/add-extension", "dep:rustls-pki-types", "dep:tokio-rustls"]
tls-client-auth = ["tonic/tls"]
tls-client-auth = ["tonic/tls-ring"]
types = ["dep:tonic-types"]
h2c = ["dep:hyper", "dep:tower", "dep:http", "dep:hyper-util"]
cancellation = ["dep:tokio-util"]
Expand Down
2 changes: 1 addition & 1 deletion interop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ hyper = "1"
prost = "0.13"
tokio = {version = "1.0", features = ["rt-multi-thread", "time", "macros"]}
tokio-stream = "0.1"
tonic = {path = "../tonic", features = ["tls"]}
tonic = {path = "../tonic", features = ["tls-ring"]}
tower = "0.5"
tracing-subscriber = {version = "0.3"}

Expand Down
22 changes: 0 additions & 22 deletions tonic-build/src/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,28 +600,6 @@ impl Builder {
self
}

/// Compile the .proto files and execute code generation.
#[deprecated(since = "0.12.3", note = "renamed to `compile_protos()`")]
pub fn compile(
self,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> io::Result<()> {
self.compile_protos(protos, includes)
}

/// Compile the .proto files and execute code generation using a custom
/// `prost_build::Config`. The provided config will be updated with this builder's config.
#[deprecated(since = "0.12.3", note = "renamed to `compile_protos_with_config()`")]
pub fn compile_with_config(
self,
config: Config,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> io::Result<()> {
self.compile_protos_with_config(config, protos, includes)
}

/// Compile the .proto files and execute code generation.
pub fn compile_protos(
self,
Expand Down
8 changes: 0 additions & 8 deletions tonic-reflection/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use tonic::Status;

/// v1 interface for the gRPC Reflection Service server.
pub mod v1;
/// Deprecated; access these via `v1` instead.
pub use v1::{ServerReflection, ServerReflectionServer}; // For backwards compatibility
/// v1alpha interface for the gRPC Reflection Service server.
pub mod v1alpha;

Expand Down Expand Up @@ -75,12 +73,6 @@ impl<'b> Builder<'b> {
self
}

/// Build a v1 gRPC Reflection Service to be served via Tonic.
#[deprecated(since = "0.12.2", note = "use `build_v1()` instead")]
pub fn build(self) -> Result<v1::ServerReflectionServer<impl v1::ServerReflection>, Error> {
self.build_v1()
}

/// Build a v1 gRPC Reflection Service to be served via Tonic.
pub fn build_v1(
mut self,
Expand Down
2 changes: 1 addition & 1 deletion tonic-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ pin-project = "1"
tonic = { version = "0.13.0", path = "../tonic", default-features = false }
tower-service = "0.3"
tower-layer = "0.3"
tower-http = { version = "0.6", features = ["cors"] }
tracing = "0.1"

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt"] }
tower-http = { version = "0.6", features = ["cors"] }

[package.metadata.cargo_check_external_types]
allowed_external_types = [
Expand Down
129 changes: 2 additions & 127 deletions tonic-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@
//!
//! ## Enabling tonic services
//!
//! The easiest way to get started, is to call the [`enable`] function with your tonic service
//! and allow the tonic server to accept HTTP/1.1 requests:
//!
//! ```ignore
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let addr = "[::1]:50051".parse().unwrap();
//! let greeter = GreeterServer::new(MyGreeter::default());
//!
//! Server::builder()
//! .accept_http1(true)
//! .add_service(tonic_web::enable(greeter))
//! .serve(addr)
//! .await?;
//!
//! Ok(())
//! }
//! ```
//! This will apply a default configuration that works well with grpc-web clients out of the box.
//!
//! You can customize the CORS configuration composing the [`GrpcWebLayer`] with the cors layer of your choice.
//!
//! ```ignore
Expand Down Expand Up @@ -63,7 +43,8 @@
//! // No need to enable HTTP/1
//! Server::builder()
//! .tls_config(ServerTlsConfig::new().identity(identity))?
//! .add_service(tonic_web::enable(greeter))
//! .layer(GrpcWebLayer::new())
//! .add_service(greeter)
//! .serve(addr)
//! .await?;
//!
Expand All @@ -87,7 +68,6 @@
//! [`tonic_web`]: https://github.com/hyperium/tonic
//! [grpc-web]: https://github.com/grpc/grpc-web
//! [tower]: https://github.com/tower-rs/tower
//! [`enable`]: crate::enable()
#![warn(
missing_debug_implementations,
missing_docs,
Expand All @@ -107,111 +87,6 @@ mod client;
mod layer;
mod service;

use http::header::HeaderName;
use pin_project::pin_project;
use std::{
fmt,
future::Future,
pin::Pin,
task::{Context, Poll},
time::Duration,
};
use tonic::{body::Body, server::NamedService, Status};
use tower_http::cors::{AllowOrigin, CorsLayer};
use tower_layer::Layer;
use tower_service::Service;

const DEFAULT_MAX_AGE: Duration = Duration::from_secs(24 * 60 * 60);
const DEFAULT_EXPOSED_HEADERS: [HeaderName; 3] = [
Status::GRPC_STATUS,
Status::GRPC_MESSAGE,
Status::GRPC_STATUS_DETAILS,
];
const DEFAULT_ALLOW_HEADERS: [HeaderName; 4] = [
HeaderName::from_static("x-grpc-web"),
http::header::CONTENT_TYPE,
HeaderName::from_static("x-user-agent"),
HeaderName::from_static("grpc-timeout"),
];

/// Enable a tonic service to handle grpc-web requests with the default configuration.
///
/// You can customize the CORS configuration composing the [`GrpcWebLayer`] with the cors layer of your choice.
#[deprecated(
since = "0.12.4",
note = "compose the `GrpcWebLayer` with the cors layer of your choice"
)]
pub fn enable<S, B>(service: S) -> CorsGrpcWeb<S>
where
S: Service<B>,
{
let cors = CorsLayer::new()
.allow_origin(AllowOrigin::mirror_request())
.allow_credentials(true)
.max_age(DEFAULT_MAX_AGE)
.expose_headers(DEFAULT_EXPOSED_HEADERS)
.allow_headers(DEFAULT_ALLOW_HEADERS);

tower_layer::layer_fn(|s| CorsGrpcWeb(cors.layer(s))).layer(GrpcWebService::new(service))
}

/// A newtype wrapper around [`GrpcWebLayer`] and [`tower_http::cors::CorsLayer`] to allow
/// `tonic_web::enable` to implement the [`NamedService`] trait.
#[derive(Debug, Clone)]
pub struct CorsGrpcWeb<S>(tower_http::cors::Cors<GrpcWebService<S>>);

impl<S, B> Service<http::Request<B>> for CorsGrpcWeb<S>
where
S: Service<http::Request<Body>, Response = http::Response<Body>>,
B: http_body::Body<Data = bytes::Bytes> + Send + 'static,
B::Error: Into<BoxError> + std::fmt::Display,
{
type Response = S::Response;
type Error = S::Error;
type Future = CorsGrpcWebResponseFuture<S::Future>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
<tower_http::cors::Cors<GrpcWebService<S>> as Service<http::Request<B>>>::poll_ready(
&mut self.0,
cx,
)
}

fn call(&mut self, req: http::Request<B>) -> Self::Future {
CorsGrpcWebResponseFuture(self.0.call(req))
}
}

/// Response Future for the [`CorsGrpcWeb`].
#[pin_project]
pub struct CorsGrpcWebResponseFuture<F>(
#[pin] tower_http::cors::ResponseFuture<service::ResponseFuture<F>>,
);

impl<F, E> Future for CorsGrpcWebResponseFuture<F>
where
F: Future<Output = Result<http::Response<Body>, E>>,
{
type Output = Result<http::Response<Body>, E>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.project().0.poll(cx)
}
}

impl<F> fmt::Debug for CorsGrpcWebResponseFuture<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("CorsGrpcWebResponseFuture").finish()
}
}

impl<S> NamedService for CorsGrpcWeb<S>
where
S: NamedService,
{
const NAME: &'static str = S::NAME;
}

type BoxError = Box<dyn std::error::Error + Send + Sync>;

pub(crate) mod util {
Expand Down
2 changes: 0 additions & 2 deletions tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ zstd = ["dep:zstd"]
default = ["transport", "codegen", "prost"]
prost = ["dep:prost"]
_tls-any = ["dep:rustls-pki-types", "dep:tokio-rustls", "dep:tokio", "tokio?/rt", "tokio?/macros"] # Internal. Please choose one of `tls-ring` or `tls-aws-lc`
tls = ["tls-ring"] # Deprecated. Please use `tls-ring` or `tls-aws-lc` instead.
tls-ring = ["_tls-any", "tokio-rustls/ring"]
tls-aws-lc = ["_tls-any", "tokio-rustls/aws-lc-rs"]
tls-roots = ["tls-native-roots"] # Deprecated. Please use `tls-native-roots` instead.
tls-native-roots = ["_tls-any", "channel", "dep:rustls-native-certs"]
tls-webpki-roots = ["_tls-any","channel", "dep:webpki-roots"]
router = ["dep:axum", "dep:tower", "tower?/util"]
Expand Down
2 changes: 0 additions & 2 deletions tonic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
//! - `router`: Enables the [`axum`] based service router. Enabled by default.
//! - `codegen`: Enables all the required exports and optional dependencies required
//! for [`tonic-build`]. Enabled by default.
//! - `tls`: Deprecated. An alias to `tls-ring`
//! - `tls-ring`: Enables the [`rustls`] based TLS options for the `transport` feature using
//! the [`ring`]` libcrypto provider. Not enabled by default.
//! - `tls-aws-lc`: Enables the [`rustls`] based TLS options for the `transport` feature using
//! the [`aws-lc-rs`] libcrypto provider. Not enabled by default.
//! - `tls-roots`: Deprecated. An alias to `tls-native-roots` feature.
//! - `tls-native-roots`: Adds system trust roots to [`rustls`]-based gRPC clients using the
//! [`rustls-native-certs`] crate. Not enabled by default.
//! - `tls-webpki-roots`: Add the standard trust roots from the [`webpki-roots`] crate to
Expand Down
6 changes: 3 additions & 3 deletions tonic/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,20 @@ impl<T> Request<T> {
/// Extensions can be set in interceptors:
///
/// ```no_run
/// use tonic::{Request, service::interceptor};
/// use tonic::{Request, Status};
///
/// #[derive(Clone)] // Extensions must be Clone
/// struct MyExtension {
/// some_piece_of_data: String,
/// }
///
/// interceptor(|mut request: Request<()>| {
/// fn intercept(mut request: Request<()>) -> Result<Request<()>, Status> {
/// request.extensions_mut().insert(MyExtension {
/// some_piece_of_data: "foo".to_string(),
/// });
///
/// Ok(request)
/// });
/// }
/// ```
///
/// And picked up by RPCs:
Expand Down
12 changes: 0 additions & 12 deletions tonic/src/service/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,7 @@ where
}
}

/// Create a new interceptor layer.
///
/// See [`Interceptor`] for more details.
#[deprecated(since = "0.12.4", note = "use `InterceptorLayer::new()` instead")]
pub fn interceptor<I>(interceptor: I) -> InterceptorLayer<I>
where
I: Interceptor,
{
InterceptorLayer { interceptor }
}

/// A gRPC interceptor that can be used as a [`Layer`],
/// created by calling [`interceptor`].
///
/// See [`Interceptor`] for more details.
#[derive(Debug, Clone, Copy)]
Expand Down
3 changes: 0 additions & 3 deletions tonic/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ pub(crate) mod layered;
#[cfg(feature = "router")]
pub(crate) mod router;

#[doc(inline)]
#[allow(deprecated)]
pub use self::interceptor::interceptor;
#[doc(inline)]
pub use self::interceptor::{Interceptor, InterceptorLayer};
pub use self::layered::{LayerExt, Layered};
Expand Down
6 changes: 0 additions & 6 deletions tonic/src/service/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ impl Routes {
}
}

/// Convert this `Routes` into an [`axum::Router`].
#[deprecated(since = "0.12.2", note = "Use `Routes::into_axum_router` instead.")]
pub fn into_router(self) -> axum::Router {
self.into_axum_router()
}

/// Convert this `Routes` into an [`axum::Router`].
pub fn into_axum_router(self) -> axum::Router {
self.router
Expand Down
2 changes: 0 additions & 2 deletions tonic/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ pub use self::error::Error;
#[doc(inline)]
#[cfg(feature = "server")]
pub use self::server::Server;
/// Deprecated. Please use [`crate::status::TimeoutExpired`] instead.
pub use crate::status::TimeoutExpired;

#[cfg(feature = "_tls-any")]
pub use self::tls::Certificate;
Expand Down
21 changes: 3 additions & 18 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl<L> Server<L> {
/// # use tower_service::Service;
/// use tower::ServiceBuilder;
/// use std::time::Duration;
/// use tonic::{Request, Status, service::interceptor};
/// use tonic::{Request, Status, service::InterceptorLayer};
///
/// fn auth_interceptor(request: Request<()>) -> Result<Request<()>, Status> {
/// if valid_credentials(&request) {
Expand All @@ -488,8 +488,8 @@ impl<L> Server<L> {
/// let layer = ServiceBuilder::new()
/// .load_shed()
/// .timeout(Duration::from_secs(30))
/// .layer(interceptor(auth_interceptor))
/// .layer(interceptor(some_other_interceptor))
/// .layer(InterceptorLayer::new(auth_interceptor))
/// .layer(InterceptorLayer::new(some_other_interceptor))
/// .into_inner();
///
/// Server::builder().layer(layer);
Expand Down Expand Up @@ -764,12 +764,6 @@ impl<L> Router<L> {
self
}

/// Convert this tonic `Router` into an axum `Router` consuming the tonic one.
#[deprecated(since = "0.12.2", note = "Use `Routes::into_axum_router` instead.")]
pub fn into_router(self) -> axum::Router {
self.routes.into_axum_router()
}

/// Consume this [`Server`] creating a future that will execute the server
/// on [tokio]'s default executor.
///
Expand Down Expand Up @@ -885,15 +879,6 @@ impl<L> Router<L> {
.serve_with_shutdown(self.routes.prepare(), incoming, Some(signal))
.await
}

/// Create a tower service out of a router.
#[deprecated(since = "0.12.4", note = "compose the layers and the `Routes`")]
pub fn into_service<ResBody>(self) -> L::Service
where
L: Layer<Routes>,
{
self.server.service_builder.service(self.routes.prepare())
}
}

impl<L> fmt::Debug for Server<L> {
Expand Down

0 comments on commit f4a879d

Please sign in to comment.