Skip to content

Commit

Permalink
Fix typos (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored Nov 21, 2024
1 parent f35094f commit f7bb838
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/poem/local-server-with-browser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn main() -> Result<(), std::io::Error> {

// To test port assignment, run two instances of this example at once.
//
// For ports <1024, running with administrator priveledges would be needed
// For ports <1024, running with administrator privileges would be needed
// on Unix. For port 0, the OS would assign a port and we'd need to find out
// what that port's number is.
let (min_port, max_port) = (8080, 8085);
Expand Down
16 changes: 8 additions & 8 deletions poem-grpc-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(crate) fn generate(config: &GrpcConfig, service: &Service, buf: &mut String)
#[allow(unused_imports)]
pub struct #server_ident<T> {
inner: ::std::sync::Arc<T>,
send_compressd: ::std::option::Option<#crate_name::CompressionEncoding>,
send_compressed: ::std::option::Option<#crate_name::CompressionEncoding>,
accept_compressed: ::std::sync::Arc<[#crate_name::CompressionEncoding]>,
}

Expand All @@ -110,7 +110,7 @@ pub(crate) fn generate(config: &GrpcConfig, service: &Service, buf: &mut String)
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
send_compressd: self.send_compressd,
send_compressed: self.send_compressed,
accept_compressed: self.accept_compressed.clone(),
}
}
Expand All @@ -127,15 +127,15 @@ pub(crate) fn generate(config: &GrpcConfig, service: &Service, buf: &mut String)
pub fn new(service: T) -> Self {
Self {
inner: ::std::sync::Arc::new(service),
send_compressd: ::std::option::Option::None,
send_compressed: ::std::option::Option::None,
accept_compressed: ::std::sync::Arc::new([]),
}
}

/// Set the compression encoding for sending
pub fn send_compressed(self, encoding: #crate_name::CompressionEncoding) -> Self {
Self {
send_compressd: Some(encoding),
send_compressed: Some(encoding),
..self
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ fn generate_unary(codec_list: &[Path], method_info: MethodInfo) -> TokenStream {
crate_name,
codec_list,
quote! {
#crate_name::server::GrpcServer::new(codec, server.send_compressd, &server.accept_compressed).unary(#proxy_service_ident(server.inner.clone()), req).await
#crate_name::server::GrpcServer::new(codec, server.send_compressed, &server.accept_compressed).unary(#proxy_service_ident(server.inner.clone()), req).await
},
);

Expand Down Expand Up @@ -270,7 +270,7 @@ fn generate_client_streaming(codec_list: &[Path], method_info: MethodInfo) -> To
crate_name,
codec_list,
quote! {
#crate_name::server::GrpcServer::new(codec, server.send_compressd, &server.accept_compressed).client_streaming(#proxy_service_ident(server.inner.clone()), req).await
#crate_name::server::GrpcServer::new(codec, server.send_compressed, &server.accept_compressed).client_streaming(#proxy_service_ident(server.inner.clone()), req).await
},
);

Expand Down Expand Up @@ -314,7 +314,7 @@ fn generate_server_streaming(codec_list: &[Path], method_info: MethodInfo) -> To
crate_name,
codec_list,
quote! {
#crate_name::server::GrpcServer::new(codec, server.send_compressd, &server.accept_compressed).server_streaming(#proxy_service_ident(server.inner.clone()), req).await
#crate_name::server::GrpcServer::new(codec, server.send_compressed, &server.accept_compressed).server_streaming(#proxy_service_ident(server.inner.clone()), req).await
},
);

Expand Down Expand Up @@ -358,7 +358,7 @@ fn generate_bidirectional_streaming(codec_list: &[Path], method_info: MethodInfo
crate_name,
codec_list,
quote! {
#crate_name::server::GrpcServer::new(codec, server.send_compressd, &server.accept_compressed).bidirectional_streaming(#proxy_service_ident(server.inner.clone()), req).await
#crate_name::server::GrpcServer::new(codec, server.send_compressed, &server.accept_compressed).bidirectional_streaming(#proxy_service_ident(server.inner.clone()), req).await
},
);

Expand Down
30 changes: 15 additions & 15 deletions poem-grpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl ClientConfigBuilder {
#[derive(Clone)]
pub struct GrpcClient {
ep: Arc<dyn DynEndpoint<Output = HttpResponse> + 'static>,
send_compressd: Option<CompressionEncoding>,
send_compressed: Option<CompressionEncoding>,
accept_compressed: Arc<[CompressionEncoding]>,
}

Expand All @@ -181,7 +181,7 @@ impl GrpcClient {
pub fn new(config: ClientConfig) -> Self {
Self {
ep: create_client_endpoint(config),
send_compressd: None,
send_compressed: None,
accept_compressed: Arc::new([]),
}
}
Expand All @@ -194,13 +194,13 @@ impl GrpcClient {
{
Self {
ep: Arc::new(ToDynEndpoint(ep.map_to_response())),
send_compressd: None,
send_compressed: None,
accept_compressed: Arc::new([]),
}
}

pub fn set_send_compressed(&mut self, encoding: CompressionEncoding) {
self.send_compressd = Some(encoding);
self.send_compressed = Some(encoding);
}

pub fn set_accept_compressed(&mut self, encodings: impl Into<Arc<[CompressionEncoding]>>) {
Expand Down Expand Up @@ -230,11 +230,11 @@ impl GrpcClient {
extensions,
} = request;
let mut http_request =
create_http_request::<T>(path, metadata, extensions, self.send_compressd);
create_http_request::<T>(path, metadata, extensions, self.send_compressed);
http_request.set_body(create_encode_request_body(
codec.encoder(),
Streaming::new(futures_util::stream::once(async move { Ok(message) })),
self.send_compressd,
self.send_compressed,
));

let mut resp = self
Expand Down Expand Up @@ -279,11 +279,11 @@ impl GrpcClient {
extensions,
} = request;
let mut http_request =
create_http_request::<T>(path, metadata, extensions, self.send_compressd);
create_http_request::<T>(path, metadata, extensions, self.send_compressed);
http_request.set_body(create_encode_request_body(
codec.encoder(),
message,
self.send_compressd,
self.send_compressed,
));

let mut resp = self
Expand Down Expand Up @@ -328,11 +328,11 @@ impl GrpcClient {
extensions,
} = request;
let mut http_request =
create_http_request::<T>(path, metadata, extensions, self.send_compressd);
create_http_request::<T>(path, metadata, extensions, self.send_compressed);
http_request.set_body(create_encode_request_body(
codec.encoder(),
Streaming::new(futures_util::stream::once(async move { Ok(message) })),
self.send_compressd,
self.send_compressed,
));

let mut resp = self
Expand Down Expand Up @@ -373,11 +373,11 @@ impl GrpcClient {
extensions,
} = request;
let mut http_request =
create_http_request::<T>(path, metadata, extensions, self.send_compressd);
create_http_request::<T>(path, metadata, extensions, self.send_compressed);
http_request.set_body(create_encode_request_body(
codec.encoder(),
message,
self.send_compressd,
self.send_compressed,
));

let mut resp = self
Expand Down Expand Up @@ -411,7 +411,7 @@ fn create_http_request<T: Codec>(
path: &str,
metadata: Metadata,
extensions: Extensions,
send_compressd: Option<CompressionEncoding>,
send_compressed: Option<CompressionEncoding>,
) -> HttpRequest {
let mut http_request = HttpRequest::builder()
.uri_str(path)
Expand All @@ -426,10 +426,10 @@ fn create_http_request<T: Codec>(
http_request
.headers_mut()
.insert(header::TE, "trailers".parse().unwrap());
if let Some(send_compressd) = send_compressd {
if let Some(send_compressed) = send_compressed {
http_request.headers_mut().insert(
"grpc-encoding",
HeaderValue::from_str(send_compressd.as_str()).expect("BUG: invalid encoding"),
HeaderValue::from_str(send_compressed.as_str()).expect("BUG: invalid encoding"),
);
}
http_request
Expand Down
2 changes: 1 addition & 1 deletion poem-grpc/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Metadata releated types
//! Metadata related types
use std::str::FromStr;

Expand Down
38 changes: 22 additions & 16 deletions poem-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ use crate::{
#[doc(hidden)]
pub struct GrpcServer<'a, T> {
codec: T,
send_compressd: Option<CompressionEncoding>,
send_compressed: Option<CompressionEncoding>,
accept_compressed: &'a [CompressionEncoding],
}

impl<'a, T: Codec> GrpcServer<'a, T> {
#[inline]
pub fn new(
codec: T,
send_compressd: Option<CompressionEncoding>,
send_compressed: Option<CompressionEncoding>,
accept_compressed: &'a [CompressionEncoding],
) -> Self {
Self {
codec,
send_compressd,
send_compressed,
accept_compressed,
}
}
Expand Down Expand Up @@ -72,9 +72,9 @@ impl<'a, T: Codec> GrpcServer<'a, T> {
let body = create_encode_response_body(
self.codec.encoder(),
Streaming::new(futures_util::stream::once(async move { Ok(message) })),
self.send_compressd,
self.send_compressed,
);
update_http_response(&mut resp, metadata, body, self.send_compressd);
update_http_response(&mut resp, metadata, body, self.send_compressed);
}
Err(status) => resp.headers_mut().extend(status.to_headers()),
}
Expand Down Expand Up @@ -114,9 +114,9 @@ impl<'a, T: Codec> GrpcServer<'a, T> {
let body = create_encode_response_body(
self.codec.encoder(),
Streaming::new(futures_util::stream::once(async move { Ok(message) })),
self.send_compressd,
self.send_compressed,
);
update_http_response(&mut resp, metadata, body, self.send_compressd);
update_http_response(&mut resp, metadata, body, self.send_compressed);
}
Err(status) => {
resp.headers_mut().extend(status.to_headers());
Expand Down Expand Up @@ -161,9 +161,12 @@ impl<'a, T: Codec> GrpcServer<'a, T> {
match res {
Ok(grpc_resp) => {
let GrpcResponse { metadata, message } = grpc_resp;
let body =
create_encode_response_body(self.codec.encoder(), message, self.send_compressd);
update_http_response(&mut resp, metadata, body, self.send_compressd);
let body = create_encode_response_body(
self.codec.encoder(),
message,
self.send_compressed,
);
update_http_response(&mut resp, metadata, body, self.send_compressed);
}
Err(status) => {
resp.headers_mut().extend(status.to_headers());
Expand Down Expand Up @@ -202,9 +205,12 @@ impl<'a, T: Codec> GrpcServer<'a, T> {
match res {
Ok(grpc_resp) => {
let GrpcResponse { metadata, message } = grpc_resp;
let body =
create_encode_response_body(self.codec.encoder(), message, self.send_compressd);
update_http_response(&mut resp, metadata, body, self.send_compressd);
let body = create_encode_response_body(
self.codec.encoder(),
message,
self.send_compressed,
);
update_http_response(&mut resp, metadata, body, self.send_compressed);
}
Err(status) => {
resp.headers_mut().extend(status.to_headers());
Expand All @@ -219,13 +225,13 @@ fn update_http_response(
resp: &mut Response,
metadata: Metadata,
body: Body,
send_compressd: Option<CompressionEncoding>,
send_compressed: Option<CompressionEncoding>,
) {
resp.headers_mut().extend(metadata.headers);
if let Some(send_compressd) = send_compressd {
if let Some(send_compressed) = send_compressed {
resp.headers_mut().insert(
"grpc-encoding",
HeaderValue::from_str(send_compressd.as_str()).expect("BUG: invalid encoding"),
HeaderValue::from_str(send_compressed.as_str()).expect("BUG: invalid encoding"),
);
}
resp.set_body(body);
Expand Down
6 changes: 3 additions & 3 deletions poem-openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# [4.0.0] 2024-01-06

- upgrade to `hyper1`
- added documetation on how to merge API specs [#716](https://github.com/poem-web/poem/pull/716)
- added documentation on how to merge API specs [#716](https://github.com/poem-web/poem/pull/716)
- impl Type for std::time::Duration instead of only humantime::Duration [#713](https://github.com/poem-web/poem/pull/713)

# [3.0.6] 2023-11-19
Expand Down Expand Up @@ -96,7 +96,7 @@ struct Obj {

# [3.0.1] 2023-08-02

- openapi: allows multiple secutity schemes on one operation [#621](https://github.com/poem-web/poem/issues/621)
- openapi: allows multiple security schemes on one operation [#621](https://github.com/poem-web/poem/issues/621)

# [3.0.0] 2023-06-21

Expand Down Expand Up @@ -420,7 +420,7 @@ struct Obj {

# [1.2.11] 2021-12-27

- Remove the `OpenApi::combine` method, `OpenApiSerice::new` can be passed a tuple to combine multiple API objects.
- Remove the `OpenApi::combine` method, `OpenApiService::new` can be passed a tuple to combine multiple API objects.

# [1.2.10] 2021-12-26

Expand Down
4 changes: 2 additions & 2 deletions poem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# [3.1.3] 2024-10-21

- Add `Middlware::combine_if` method.
- Add `Middleware::combine_if` method.

# [3.1.2] 2024-10-21

- Add `Middlware::combine` method to combine two middlewares.
- Add `Middleware::combine` method to combine two middlewares.

# [3.1.1] 2024-10-02

Expand Down
4 changes: 2 additions & 2 deletions poem/src/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ where
/// purpose sum type with two cases.
pub enum EitherMiddleware<A, B, E> {
/// A middlware of type `A`
/// A middleware of type `A`
A(A, PhantomData<E>),
/// B middlware of type `B`
/// B middleware of type `B`
B(B, PhantomData<E>),
}

Expand Down

0 comments on commit f7bb838

Please sign in to comment.