Skip to content

Commit bf74afc

Browse files
gw-deGunnar Westerlingtofay
authored
New mime multipart crate for hyper 1.x (#178)
* Switch mime_multipart dependency with hyper 1.0 compatible fork, fix tests Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> * Avoid using hyper re-exports and use http or bytes crate directly Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> * Fix mime multipart dependency after publishing fork Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> * Fix dependencies Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> * Update CHANGELOG.md Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> * Move http-body-util to dev-dependencies Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> * Bump up version to match changelog Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> * mime dependency needed for multipart_related feature Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> --------- Signed-off-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> Co-authored-by: Gunnar Westerling <gunnar.westerling@fokus.fraunhofer.de> Co-authored-by: Tom Fay <tom.fay@alianza.com>
1 parent 2924500 commit bf74afc

File tree

12 files changed

+58
-59
lines changed

12 files changed

+58
-59
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212

1313
### Fixed
1414

15+
## [7.0.0-rc.2] - 2025-06-10
16+
### Changed
17+
- Replace `mime_multipart` with fork for hyper 1.x
18+
1519
## [7.0.0-rc1] - 2024-05-09
1620
### Changed
1721
- Remove dependency and re-export of `hyper-old-types` which is no longer maintained.
@@ -225,7 +229,8 @@ No changes. We now think we've got enough to declare this crate stable.
225229
## [0.5.0] - 2017-09-18
226230
- Start of changelog.
227231

228-
[Unreleased]: https://github.com/Metaswitch/swagger-rs/compare/7.0.0-rc1...HEAD
232+
[Unreleased]: https://github.com/Metaswitch/swagger-rs/compare/7.0.0-rc2...HEAD
233+
[7.0.0-rc2]: https://github.com/Metaswitch/swagger-rs/compare/7.0.0-rc1...7.0.0-rc2
229234
[7.0.0-rc1]: https://github.com/Metaswitch/swagger-rs/compare/6.5.0...7.0.0-rc1
230235
[6.5.0]: https://github.com/Metaswitch/swagger-rs/compare/6.4.1...6.5.0
231236
[6.4.1]: https://github.com/Metaswitch/swagger-rs/compare/6.4.0...6.4.1

Cargo.toml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "swagger"
3-
version = "7.0.0-rc1"
3+
version = "7.0.0-rc2"
44
authors = ["Metaswitch Networks Ltd"]
55
license = "Apache-2.0"
66
description = "A set of common utilities for Rust code generated by OpenAPI Generator"
@@ -13,7 +13,7 @@ edition = "2021"
1313
[features]
1414
default = ["serdejson"]
1515
multipart_form = ["mime"]
16-
multipart_related = ["mime_multipart"]
16+
multipart_related = ["mime_multipart", "mime"]
1717
serdejson = ["serde", "serde_json"]
1818
serdevalid = ["serdejson", "serde_valid", "regex", "paste"]
1919
server = ["hyper/server"]
@@ -32,16 +32,18 @@ conversion = [
3232

3333
[dependencies]
3434
base64 = "0.22"
35+
futures = "0.3"
36+
headers = "0.4.0"
37+
http = "1"
38+
bytes = "1.8.0"
39+
hyper = "1"
3540

3641
# Conversion
3742
frunk = { version = "0.4", optional = true }
3843
frunk-enum-core = { version = "0.3", optional = true }
3944
frunk-enum-derive = { version = "0.3", optional = true }
4045
frunk_core = { version = "0.4", optional = true }
4146
frunk_derives = { version = "0.4", optional = true }
42-
futures = "0.3"
43-
headers = "0.4.0"
44-
hyper = { version = "1" }
4547

4648
# Client
4749
hyper-util = { version = "0.1.8", features = [
@@ -53,7 +55,9 @@ hyper-util = { version = "0.1.8", features = [
5355
mime = { version = "0.3", optional = true }
5456

5557
# multipart/related
56-
mime_multipart = { version = "0.6", optional = true }
58+
mime_multipart = { version = "0.10", package = "mime-multipart-hyper1", optional = true }
59+
60+
# serde
5761
paste = { version = "1", optional = true }
5862
regex = { version = "1", optional = true }
5963
serde = { version = "1.0.119", optional = true, features = ["derive"] }
@@ -77,13 +81,10 @@ hyper-tls = { version = "0.6", optional = true }
7781
native-tls = { version = "0.2", optional = true }
7882

7983
[dev-dependencies]
80-
bytes = "1.8.0"
81-
http-body-util = "0.1.2"
8284
hyper-util = { version = "0.1.8", features = ["full"] }
83-
hyper_10 = { package = "hyper", version = "0.10" }
84-
mime_026 = { package = "mime", version = "0.2.6" }
8585
tokio = { version = "1.0", features = ["macros", "rt"] }
8686
tokio-test = "0.4.4"
87+
http-body-util = "0.1.2"
8788

8889
[package.metadata.docs.rs]
8990
# Enable all features, pending https://github.com/rust-lang/rust/issues/43781 being resolved.

src/add_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
44
use crate::{Push, XSpanIdString};
55
use futures::FutureExt;
6-
use hyper::Request;
6+
use http::Request;
77
use std::marker::PhantomData;
88

99
/// Middleware wrapper service, that should be used as the outermost layer in a
10-
/// stack of hyper services. Adds a context to a plain `hyper::Request` that can be
10+
/// stack of hyper services. Adds a context to a plain `http::Request` that can be
1111
/// used by subsequent layers in the stack.
1212
#[derive(Debug)]
1313
pub struct AddContextMakeService<T, C>
@@ -55,7 +55,7 @@ where
5555
}
5656

5757
/// Middleware wrapper service, that should be used as the outermost layer in a
58-
/// stack of hyper services. Adds a context to a plain `hyper::Request` that can be
58+
/// stack of hyper services. Adds a context to a plain `http::Request` that can be
5959
/// used by subsequent layers in the stack. The `AddContextService` struct should
6060
/// not usually be used directly - when constructing a hyper stack use
6161
/// `AddContextMakeService`, which will create `AddContextService` instances as needed.

src/auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::context::Push;
44
use futures::future::FutureExt;
55
use headers::authorization::{Basic, Bearer, Credentials};
66
use headers::Authorization as Header;
7-
use hyper::header::AUTHORIZATION;
7+
use http::header::AUTHORIZATION;
8+
use http::{HeaderMap, Request};
89
use hyper::service::Service;
9-
use hyper::{HeaderMap, Request};
1010
use std::collections::BTreeSet;
1111
use std::marker::PhantomData;
1212
use std::string::ToString;
@@ -248,10 +248,10 @@ mod tests {
248248
use super::*;
249249
use crate::context::{ContextBuilder, Has};
250250
use crate::EmptyContext;
251+
use bytes::Bytes;
252+
use http::Response;
251253
use http_body_util::Full;
252-
use hyper::body::Bytes;
253254
use hyper::service::Service;
254-
use hyper::Response;
255255

256256
struct MakeTestService;
257257

src/body.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/// Helper methods to act on hyper::Body
1+
/// Helper methods for processing body
2+
use bytes::Bytes;
23
use futures::stream::{Stream, StreamExt};
3-
use hyper::body::Bytes;
44

5-
/// Additional function for hyper::Body
5+
/// Additional function for converting body stream into Vec<u8>
66
pub trait BodyExt {
77
/// Raw body type
88
type Raw;

src/composites.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//! Use by passing `hyper::server::MakeService` instances to a `CompositeMakeService`
44
//! together with the base path for requests that should be handled by that service.
55
use futures::future::{BoxFuture, FutureExt, TryFutureExt};
6+
use http::{Request, Response, StatusCode};
67
use hyper::service::Service;
7-
use hyper::{Request, Response, StatusCode};
88
use std::fmt;
99
use std::future::Future;
1010
use std::net::SocketAddr;

src/context.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::XSpanIdString;
1919
/// # use std::marker::PhantomData;
2020
/// # use std::pin::Pin;
2121
/// # use swagger::context::*;
22-
/// # use hyper::body::Bytes;
22+
/// # use bytes::Bytes;
2323
/// # use http_body_util::Empty;
2424
/// #
2525
/// # struct MyItem;
@@ -29,17 +29,17 @@ use crate::XSpanIdString;
2929
/// marker: PhantomData<C>,
3030
/// }
3131
///
32-
/// impl<C, B> hyper::service::Service<(hyper::Request<B>, C)> for MyService<C>
32+
/// impl<C, B> hyper::service::Service<(http::Request<B>, C)> for MyService<C>
3333
/// where C: Has<MyItem> + Send + 'static
3434
/// {
35-
/// type Response = hyper::Response<Empty<Bytes>>;
35+
/// type Response = http::Response<Empty<Bytes>>;
3636
/// type Error = std::io::Error;
3737
/// type Future = Pin<Box<dyn Future<Output=Result<Self::Response, Self::Error>>>>;
3838
///
39-
/// fn call(&self, req : (hyper::Request<B>, C)) -> Self::Future {
39+
/// fn call(&self, req : (http::Request<B>, C)) -> Self::Future {
4040
/// let (_, context) = req;
4141
/// do_something_with_my_item(Has::<MyItem>::get(&context));
42-
/// Box::pin(ok(hyper::Response::new(Empty::<Bytes>::new())))
42+
/// Box::pin(ok(http::Response::new(Empty::<Bytes>::new())))
4343
/// }
4444
/// }
4545
/// ```
@@ -70,19 +70,19 @@ pub trait Has<T> {
7070
/// marker: PhantomData<C>,
7171
/// }
7272
///
73-
/// impl<T, C, D, E, B> hyper::service::Service<(hyper::Request<B>, C)> for MiddlewareService<T, C>
73+
/// impl<T, C, D, E, B> hyper::service::Service<(http::Request<B>, C)> for MiddlewareService<T, C>
7474
/// where
7575
/// C: Pop<MyItem1, Result=D> + Send + 'static,
7676
/// D: Pop<MyItem2, Result=E>,
7777
/// E: Pop<MyItem3>,
7878
/// E::Result: Send + 'static,
79-
/// T: hyper::service::Service<(hyper::Request<B>, E::Result)>
79+
/// T: hyper::service::Service<(http::Request<B>, E::Result)>
8080
/// {
8181
/// type Response = T::Response;
8282
/// type Error = T::Error;
8383
/// type Future = T::Future;
8484
///
85-
/// fn call(&self, req : (hyper::Request<B>, C)) -> Self::Future {
85+
/// fn call(&self, req : (http::Request<B>, C)) -> Self::Future {
8686
/// let (request, context) = req;
8787
///
8888
/// // type annotations optional, included for illustrative purposes
@@ -118,19 +118,19 @@ pub trait Pop<T> {
118118
/// marker: PhantomData<C>,
119119
/// }
120120
///
121-
/// impl<T, C, D, E, B> hyper::service::Service<(hyper::Request<B>, C)> for MiddlewareService<T, C>
121+
/// impl<T, C, D, E, B> hyper::service::Service<(http::Request<B>, C)> for MiddlewareService<T, C>
122122
/// where
123123
/// C: Push<MyItem1, Result=D> + Send + 'static,
124124
/// D: Push<MyItem2, Result=E>,
125125
/// E: Push<MyItem3>,
126126
/// E::Result: Send + 'static,
127-
/// T: hyper::service::Service<(hyper::Request<B>, E::Result)>
127+
/// T: hyper::service::Service<(http::Request<B>, E::Result)>
128128
/// {
129129
/// type Response = T::Response;
130130
/// type Error = T::Error;
131131
/// type Future = T::Future;
132132
///
133-
/// fn call(&self, req : (hyper::Request<B>, C)) -> Self::Future {
133+
/// fn call(&self, req : (http::Request<B>, C)) -> Self::Future {
134134
/// let (request, context) = req;
135135
/// let context = context
136136
/// .push(MyItem1{})

src/drop_context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
//! Hyper service that drops a context to an incoming request and passes it on
22
//! to a wrapped service.
33
4-
use hyper::Request;
4+
use http::Request;
55
use std::marker::PhantomData;
66

77
use futures::future::FutureExt as _;
88

99
/// Middleware wrapper service that drops the context from the incoming request
10-
/// and passes the plain `hyper::Request` to the wrapped service.
10+
/// and passes the plain `http::Request` to the wrapped service.
1111
///
12-
/// This service can be used to to include services that take a plain `hyper::Request`
12+
/// This service can be used to to include services that take a plain `http::Request`
1313
/// in a `CompositeService` wrapped in an `AddContextService`.
1414
///
1515
/// Example Usage
1616
/// =============
1717
///
1818
/// In the following example `SwaggerService` implements `hyper::service::MakeService`
19-
/// with `Request = (hyper::Request, SomeContext)`, and `PlainService` implements it
20-
/// with `Request = hyper::Request`
19+
/// with `Request = (http::Request, SomeContext)`, and `PlainService` implements it
20+
/// with `Request = http::Request`
2121
///
2222
/// ```ignore
2323
/// let swagger_service_one = SwaggerService::new();
@@ -85,10 +85,10 @@ where
8585
/// # use hyper_util::rt::TokioExecutor;
8686
/// # use hyper_util::service::TowerToHyperService;
8787
/// # use http_body_util::Empty;
88-
/// # use hyper::body::Bytes;
88+
/// # use bytes::Bytes;
8989
/// let client = Client::builder(TokioExecutor::new()).build_http();
9090
/// let client = DropContextService::new(TowerToHyperService::new(client));
91-
/// let request = (hyper::Request::get("http://www.google.com").body(Empty::<Bytes>::new()).unwrap());
91+
/// let request = (http::Request::get("http://www.google.com").body(Empty::<Bytes>::new()).unwrap());
9292
/// let context = "Some Context".to_string();
9393
///
9494
/// let response = client.call((request, context));

src/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct XSpanIdString(pub String);
1111
impl XSpanIdString {
1212
/// Extract an X-Span-ID from a request header if present, and if not
1313
/// generate a new one.
14-
pub fn get_or_generate<T>(req: &hyper::Request<T>) -> Self {
14+
pub fn get_or_generate<T>(req: &http::Request<T>) -> Self {
1515
let x_span_id = req.headers().get(X_SPAN_ID);
1616

1717
x_span_id

src/multipart/form.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Helper functions for multipart/form-data support
2-
use hyper::header::{HeaderMap, CONTENT_TYPE};
2+
use http::header::{HeaderMap, CONTENT_TYPE};
33

44
/// Utility function to get the multipart boundary marker (if any) from the Headers.
55
pub fn boundary(headers: &HeaderMap) -> Option<String> {

0 commit comments

Comments
 (0)