Skip to content

Commit

Permalink
chore: some code clean up and typo fix (#786)
Browse files Browse the repository at this point in the history
* chore: some code clean up and typo fix

* more

---------

Co-authored-by: hzlinyiyu <[email protected]>
  • Loading branch information
attila-lin and hzlinyiyu-netease authored Mar 30, 2024
1 parent 371baa8 commit 0c16a9b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion poem-grpc/src/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Reflection {
let fd_iter = std::mem::take(&mut this.file_descriptor_sets)
.into_iter()
.flat_map(|fds| fds.file.into_iter());
let mut files = HashMap::new();
let mut files = HashMap::with_capacity(fd_iter.size_hint().0);

for fd in fd_iter {
let fd = Arc::new(fd);
Expand Down
2 changes: 1 addition & 1 deletion poem-openapi/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ impl<T: OpenApi, W: Webhook> IntoEndpoint for OpenApiService<T, W> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{types::Type, OpenApi};
use crate::OpenApi;

#[test]
fn extra_response_headers() {
Expand Down
3 changes: 1 addition & 2 deletions poem/src/listener/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ impl Listener for BoxListener {

#[cfg(test)]
mod tests {
use super::{AcceptorExt, *};
use crate::listener::TcpListener;
use super::*;

#[tokio::test]
async fn combined_listener() {
Expand Down
10 changes: 5 additions & 5 deletions poem/src/listener/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ impl RustlsConfig {
.map(|fallback| fallback.create_certificate_key())
.transpose()?
.map(Arc::new);
let mut certifcate_keys = HashMap::new();
let mut certificate_keys = HashMap::with_capacity(self.certificates.len());

for (name, certificate) in &self.certificates {
certifcate_keys.insert(
certificate_keys.insert(
name.clone(),
Arc::new(certificate.create_certificate_key()?),
);
Expand All @@ -252,7 +252,7 @@ impl RustlsConfig {
};

let mut server_config = builder.with_cert_resolver(Arc::new(ResolveServerCert {
certifcate_keys,
certificate_keys,
fallback,
}));
server_config.alpn_protocols = vec!["h2".into(), "http/1.1".into()];
Expand Down Expand Up @@ -401,15 +401,15 @@ where

#[derive(Debug)]
struct ResolveServerCert {
certifcate_keys: HashMap<String, Arc<CertifiedKey>>,
certificate_keys: HashMap<String, Arc<CertifiedKey>>,
fallback: Option<Arc<CertifiedKey>>,
}

impl ResolvesServerCert for ResolveServerCert {
fn resolve(&self, client_hello: ClientHello) -> Option<Arc<CertifiedKey>> {
client_hello
.server_name()
.and_then(|name| self.certifcate_keys.get(name).cloned())
.and_then(|name| self.certificate_keys.get(name).cloned())
.or_else(|| self.fallback.clone())
}
}
Expand Down
2 changes: 1 addition & 1 deletion poem/src/middleware/cookie_jar_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<E: Endpoint> Endpoint for CookieJarManagerEndpoint<E> {
async fn call(&self, mut req: Request) -> Result<Self::Output> {
if req.state().cookie_jar.is_none() {
let mut cookie_jar = CookieJar::extract_from_headers(req.headers());
cookie_jar.key = self.key.clone();
cookie_jar.key.clone_from(&self.key);
req.state_mut().cookie_jar = Some(cookie_jar.clone());
let mut resp = self.inner.call(req).await?.into_response();
cookie_jar.append_delta_to_headers(resp.headers_mut());
Expand Down
2 changes: 1 addition & 1 deletion poem/src/route/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ fn normalize_path(path: &str) -> String {
#[cfg(test)]
mod tests {
use futures_util::lock::Mutex;
use http::{StatusCode, Uri};
use http::StatusCode;

use super::*;
use crate::{endpoint::make_sync, handler, test::TestClient, Error};
Expand Down
6 changes: 1 addition & 5 deletions poem/src/route/router_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::{
handler,
http::{Method, StatusCode},
test::TestClient,
};
use crate::{handler, http::StatusCode, test::TestClient};

#[tokio::test]
async fn method_not_allowed() {
Expand Down
2 changes: 0 additions & 2 deletions poem/src/web/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ impl<'a> FromRequest<'a> for Accept {
mod tests {
use std::str::FromStr;

use http::header;

use super::*;

#[tokio::test]
Expand Down

0 comments on commit 0c16a9b

Please sign in to comment.