feat!: remove codegen dependency on compression feature (#1004)
This commit is contained in:
@@ -79,20 +79,20 @@ pub fn generate<T: Service>(
|
||||
#service_ident::new(InterceptedService::new(inner, interceptor))
|
||||
}
|
||||
|
||||
/// Compress requests with `gzip`.
|
||||
/// Compress requests with the given encoding.
|
||||
///
|
||||
/// This requires the server to support it otherwise it might respond with an
|
||||
/// error.
|
||||
#[must_use]
|
||||
pub fn send_gzip(mut self) -> Self {
|
||||
self.inner = self.inner.send_gzip();
|
||||
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||
self.inner = self.inner.send_compressed(encoding);
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable decompressing responses with `gzip`.
|
||||
/// Enable decompressing responses.
|
||||
#[must_use]
|
||||
pub fn accept_gzip(mut self) -> Self {
|
||||
self.inner = self.inner.accept_gzip();
|
||||
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||
self.inner = self.inner.accept_compressed(encoding);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
+14
-26
@@ -39,32 +39,20 @@ pub fn generate<T: Service>(
|
||||
let mod_attributes = attributes.for_mod(package);
|
||||
let struct_attributes = attributes.for_struct(&path);
|
||||
|
||||
let compression_enabled = cfg!(feature = "compression");
|
||||
let configure_compression_methods = quote! {
|
||||
/// Enable decompressing requests with the given encoding.
|
||||
#[must_use]
|
||||
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||
self.accept_compression_encodings.enable(encoding);
|
||||
self
|
||||
}
|
||||
|
||||
let compression_config_ty = if compression_enabled {
|
||||
quote! { EnabledCompressionEncodings }
|
||||
} else {
|
||||
quote! { () }
|
||||
};
|
||||
|
||||
let configure_compression_methods = if compression_enabled {
|
||||
quote! {
|
||||
/// Enable decompressing requests with `gzip`.
|
||||
#[must_use]
|
||||
pub fn accept_gzip(mut self) -> Self {
|
||||
self.accept_compression_encodings.enable_gzip();
|
||||
self
|
||||
}
|
||||
|
||||
/// Compress responses with `gzip`, if the client supports it.
|
||||
#[must_use]
|
||||
pub fn send_gzip(mut self) -> Self {
|
||||
self.send_compression_encodings.enable_gzip();
|
||||
self
|
||||
}
|
||||
/// Compress responses with the given encoding, if the client supports it.
|
||||
#[must_use]
|
||||
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||
self.send_compression_encodings.enable(encoding);
|
||||
self
|
||||
}
|
||||
} else {
|
||||
quote! {}
|
||||
};
|
||||
|
||||
quote! {
|
||||
@@ -87,8 +75,8 @@ pub fn generate<T: Service>(
|
||||
#[derive(Debug)]
|
||||
pub struct #server_service<T: #server_trait> {
|
||||
inner: _Inner<T>,
|
||||
accept_compression_encodings: #compression_config_ty,
|
||||
send_compression_encodings: #compression_config_ty,
|
||||
accept_compression_encodings: EnabledCompressionEncodings,
|
||||
send_compression_encodings: EnabledCompressionEncodings,
|
||||
}
|
||||
|
||||
struct _Inner<T>(Arc<T>);
|
||||
|
||||
Reference in New Issue
Block a user