Skip to content

Commit

Permalink
poem 3.0.0
Browse files Browse the repository at this point in the history
Co-Authored-By: hzlinyiyu <[email protected]>
  • Loading branch information
sunli829 and hzlinyiyu-netease committed Mar 30, 2024
1 parent cba2ecb commit f6bec88
Show file tree
Hide file tree
Showing 22 changed files with 63 additions and 77 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ repository = "https://github.com/poem-web/poem"
rust-version = "1.75"

[workspace.dependencies]
poem = { path = "poem", version = "2.0.1", default-features = false }
poem-derive = { path = "poem-derive", version = "2.0.1" }
poem-openapi-derive = { path = "poem-openapi-derive", version = "4.0.1" }
poem-grpc-build = { path = "poem-grpc-build", version = "0.3.0" }
poem = { path = "poem", version = "3.0.0", default-features = false }
poem-derive = { path = "poem-derive", version = "3.0.0" }
poem-openapi-derive = { path = "poem-openapi-derive", version = "5.0.0" }
poem-grpc-build = { path = "poem-grpc-build", version = "0.4.0" }

proc-macro-crate = "3.0.0"
proc-macro2 = "1.0.29"
Expand All @@ -42,7 +42,7 @@ futures-util = "0.3.17"
tokio-stream = "0.1.8"
serde_yaml = "0.9"
quick-xml = { version = "0.31.0", features = ["serialize"] }
base64 = "0.21.0"
base64 = "0.22.0"
serde_urlencoded = "0.7.1"
indexmap = "2.0.0"
reqwest = { version = "0.12.2", default-features = false }
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion poem-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poem-derive"
version = "2.0.1"
version = "3.0.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion poem-grpc-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poem-grpc-build"
version = "0.3.0"
version = "0.4.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions poem-grpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poem-grpc"
version = "0.3.0"
version = "0.4.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down Expand Up @@ -28,7 +28,7 @@ itoa = "1.0.2"
percent-encoding = "2.1.0"
bytes.workspace = true
prost = "0.12.0"
base64 = "0.21.0"
base64.workspace = true
prost-types = "0.12.0"
tokio-stream = { workspace = true, features = ["sync"] }
serde = { workspace = true, optional = true }
Expand Down
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-lambda/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [5.0.0] 2024-03-24
# [5.0.0] 2024-03-30

- use AFIT instead of `async_trait`
- Bump `lambda_http` from `0.9` to `0.10`
Expand Down
4 changes: 2 additions & 2 deletions poem-lambda/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poem-lambda"
version = "4.0.0"
version = "5.0.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand All @@ -21,7 +21,7 @@ categories = [
[dependencies]
poem = { workspace = true, default-features = false }

lambda_http = { version = "0.10.0" }
lambda_http = { version = "0.11.0" }

[dev-dependencies]
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
2 changes: 1 addition & 1 deletion poem-openapi-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poem-openapi-derive"
version = "4.0.1"
version = "5.0.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion poem-openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [5.0.0] 2024-03-24
# [5.0.0] 2024-03-30

- use AFIT instead of `async_trait`
- add `Upload::size` method
Expand Down
2 changes: 1 addition & 1 deletion poem-openapi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poem-openapi"
version = "4.0.1"
version = "5.0.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
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
17 changes: 10 additions & 7 deletions poem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [3.0.0] 2024-03-24
# [3.0.0] 2024-03-30

- use AFIT instead of `async_trait`
- bump `priority-queue` to 2.0
- bump `x509-parser` to 0.16
- bump `nix` to 0.28
- bump `redis` to 0.25
- bump `reqwest` to 0.12
- bump `opentelemetry` to 0.22 [#784](https://github.com/poem-web/poem/pull/784)
- bump `priority-queue` to `2.0`
- bump `x509-parser` to `0.16`
- bump `nix` to `0.28`
- bump `redis` to `0.25`
- bump `reqwest` to `0.12`
- bump `opentelemetry` to `0.22` [#784](https://github.com/poem-web/poem/pull/784)
- bump `sync_wrapper` to `1.0.0`
- bump `rcgen ` to `0.13.0`
- bump `base64 ` to `0.22.0`

# [2.0.1] 2024-03-04

Expand Down
6 changes: 3 additions & 3 deletions poem/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poem"
version = "2.0.1"
version = "3.0.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down Expand Up @@ -92,7 +92,7 @@ thiserror.workspace = true
rfc7239 = "0.1.0"
mime.workspace = true
wildmatch = "2"
sync_wrapper = { version = "0.1.2", features = ["futures"] }
sync_wrapper = { version = "1.0.0", features = ["futures"] }

# Non-feature optional dependencies
multer = { version = "3.0.0", features = ["tokio"], optional = true }
Expand Down Expand Up @@ -150,7 +150,7 @@ unic-langid = { version = "0.9.0", optional = true, features = ["macros"] }
intl-memoizer = { version = "0.5.1", optional = true }
ring = { version = "0.17.7", optional = true }
reqwest = { workspace = true, features = ["json"], optional = true }
rcgen = { version = "0.12.0", optional = true }
rcgen = { version = "0.13.0", optional = true }
x509-parser = { version = "0.16.0", optional = true }
tokio-metrics = { version = "0.3.0", optional = true }
rust-embed = { version = "8.0", optional = true }
Expand Down
58 changes: 24 additions & 34 deletions poem/src/listener/acme/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use std::{
};

use http::uri::Scheme;
use rcgen::{
Certificate, CertificateParams, CustomExtension, DistinguishedName, PKCS_ECDSA_P256_SHA256,
};
use rcgen::{CertificateParams, CustomExtension, KeyPair, PKCS_ECDSA_P256_SHA256};
use tokio_rustls::{
rustls::{
crypto::ring::sign::any_ecdsa_type,
Expand Down Expand Up @@ -229,21 +227,21 @@ impl<T: Acceptor> Acceptor for AutoCertAcceptor<T> {
}

fn gen_acme_cert(domain: &str, acme_hash: &[u8]) -> IoResult<CertifiedKey> {
let mut params = CertificateParams::new(vec![domain.to_string()]);
params.alg = &PKCS_ECDSA_P256_SHA256;
params.custom_extensions = vec![CustomExtension::new_acme_identifier(acme_hash)];
let cert = Certificate::from_params(params)
.map_err(|_| IoError::new(ErrorKind::Other, "failed to generate acme certificate"))?;
let key = any_ecdsa_type(&PrivateKeyDer::Pkcs8(
cert.serialize_private_key_der().into(),
))
.unwrap();
Ok(CertifiedKey::new(
vec![CertificateDer::from(cert.serialize_der().map_err(
|_| IoError::new(ErrorKind::Other, "failed to serialize acme certificate"),
)?)],
key,
))
let keypair = KeyPair::generate_for(&PKCS_ECDSA_P256_SHA256).expect("create key pair");
let cert = CertificateParams::new(vec![domain.to_string()])
.and_then(|mut params| {
params.custom_extensions = vec![CustomExtension::new_acme_identifier(acme_hash)];
params.self_signed(&keypair)
})
.map_err(|err| {
IoError::new(
ErrorKind::Other,
format!("failed to generate acme certificate: {err}"),
)
})?;

let key = any_ecdsa_type(&PrivateKeyDer::Pkcs8(keypair.serialized_der().into())).unwrap();
Ok(CertifiedKey::new(vec![cert.der().clone()], key))
}

/// The result of [`issue_cert`] function.
Expand Down Expand Up @@ -343,31 +341,23 @@ pub async fn issue_cert<T: AsRef<str>>(
}

// send csr
let mut params = CertificateParams::new(
let keypair = KeyPair::generate_for(&PKCS_ECDSA_P256_SHA256).expect("create key pair");
let request = CertificateParams::new(
domains
.iter()
.map(|domain| domain.as_ref().to_string())
.collect::<Vec<_>>(),
);
params.distinguished_name = DistinguishedName::new();
params.alg = &PKCS_ECDSA_P256_SHA256;
let cert = Certificate::from_params(params).map_err(|err| {
)
.and_then(|params| params.serialize_request(&keypair))
.map_err(|err| {
IoError::new(
ErrorKind::Other,
format!("failed create certificate request: {err}"),
)
})?;
let pk = any_ecdsa_type(&PrivateKeyDer::Pkcs8(
cert.serialize_private_key_der().into(),
))
.unwrap();
let csr = cert.serialize_request_der().map_err(|err| {
IoError::new(
ErrorKind::Other,
format!("failed to serialize request der {err}"),
)
})?;

let pk = any_ecdsa_type(&PrivateKeyDer::Pkcs8(keypair.serialized_der().into())).unwrap();
let csr = request.der().as_ref();
let order_resp = client.send_csr(&order_resp.finalize, &csr).await?;

if order_resp.status == "invalid" {
Expand Down Expand Up @@ -403,7 +393,7 @@ pub async fn issue_cert<T: AsRef<str>>(
)
})?)
.await?;
let pkey_pem = cert.serialize_private_key_pem();
let pkey_pem = keypair.serialize_pem();
let cert_chain = rustls_pemfile::certs(&mut acme_cert_pem.as_slice())
.collect::<Result<_, _>>()
.map_err(|err| IoError::new(ErrorKind::Other, format!("invalid pem: {err}")))?;
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 f6bec88

Please sign in to comment.