Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

## [7.0.0-rc.2] - 2025-06-10
### Changed
- Replace `mime_multipart` with fork for hyper 1.x

## [7.0.0-rc1] - 2024-05-09
### Changed
- Remove dependency and re-export of `hyper-old-types` which is no longer maintained.
Expand Down Expand Up @@ -225,7 +229,8 @@ No changes. We now think we've got enough to declare this crate stable.
## [0.5.0] - 2017-09-18
- Start of changelog.

[Unreleased]: https://github.com/Metaswitch/swagger-rs/compare/7.0.0-rc1...HEAD
[Unreleased]: https://github.com/Metaswitch/swagger-rs/compare/7.0.0-rc2...HEAD
[7.0.0-rc2]: https://github.com/Metaswitch/swagger-rs/compare/7.0.0-rc1...7.0.0-rc2
[7.0.0-rc1]: https://github.com/Metaswitch/swagger-rs/compare/6.5.0...7.0.0-rc1
[6.5.0]: https://github.com/Metaswitch/swagger-rs/compare/6.4.1...6.5.0
[6.4.1]: https://github.com/Metaswitch/swagger-rs/compare/6.4.0...6.4.1
Expand Down
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "swagger"
version = "7.0.0-rc1"
version = "7.0.0-rc2"
authors = ["Metaswitch Networks Ltd"]
license = "Apache-2.0"
description = "A set of common utilities for Rust code generated by OpenAPI Generator"
Expand All @@ -13,7 +13,7 @@ edition = "2021"
[features]
default = ["serdejson"]
multipart_form = ["mime"]
multipart_related = ["mime_multipart"]
multipart_related = ["mime_multipart", "mime"]
serdejson = ["serde", "serde_json"]
serdevalid = ["serdejson", "serde_valid", "regex", "paste"]
server = ["hyper/server"]
Expand All @@ -32,16 +32,18 @@ conversion = [

[dependencies]
base64 = "0.22"
futures = "0.3"
headers = "0.4.0"
http = "1"
bytes = "1.8.0"
hyper = "1"

# Conversion
frunk = { version = "0.4", optional = true }
frunk-enum-core = { version = "0.3", optional = true }
frunk-enum-derive = { version = "0.3", optional = true }
frunk_core = { version = "0.4", optional = true }
frunk_derives = { version = "0.4", optional = true }
futures = "0.3"
headers = "0.4.0"
hyper = { version = "1" }

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

# multipart/related
mime_multipart = { version = "0.6", optional = true }
mime_multipart = { version = "0.10", package = "mime-multipart-hyper1", optional = true }

# serde
paste = { version = "1", optional = true }
regex = { version = "1", optional = true }
serde = { version = "1.0.119", optional = true, features = ["derive"] }
Expand All @@ -77,13 +81,10 @@ hyper-tls = { version = "0.6", optional = true }
native-tls = { version = "0.2", optional = true }

[dev-dependencies]
bytes = "1.8.0"
http-body-util = "0.1.2"
hyper-util = { version = "0.1.8", features = ["full"] }
hyper_10 = { package = "hyper", version = "0.10" }
mime_026 = { package = "mime", version = "0.2.6" }
tokio = { version = "1.0", features = ["macros", "rt"] }
tokio-test = "0.4.4"
http-body-util = "0.1.2"

[package.metadata.docs.rs]
# Enable all features, pending https://github.com/rust-lang/rust/issues/43781 being resolved.
Expand Down
6 changes: 3 additions & 3 deletions src/add_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

use crate::{Push, XSpanIdString};
use futures::FutureExt;
use hyper::Request;
use http::Request;
use std::marker::PhantomData;

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

/// Middleware wrapper service, that should be used as the outermost layer in a
/// stack of hyper services. Adds a context to a plain `hyper::Request` that can be
/// stack of hyper services. Adds a context to a plain `http::Request` that can be
/// used by subsequent layers in the stack. The `AddContextService` struct should
/// not usually be used directly - when constructing a hyper stack use
/// `AddContextMakeService`, which will create `AddContextService` instances as needed.
Expand Down
8 changes: 4 additions & 4 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::context::Push;
use futures::future::FutureExt;
use headers::authorization::{Basic, Bearer, Credentials};
use headers::Authorization as Header;
use hyper::header::AUTHORIZATION;
use http::header::AUTHORIZATION;
use http::{HeaderMap, Request};
use hyper::service::Service;
use hyper::{HeaderMap, Request};
use std::collections::BTreeSet;
use std::marker::PhantomData;
use std::string::ToString;
Expand Down Expand Up @@ -248,10 +248,10 @@ mod tests {
use super::*;
use crate::context::{ContextBuilder, Has};
use crate::EmptyContext;
use bytes::Bytes;
use http::Response;
use http_body_util::Full;
use hyper::body::Bytes;
use hyper::service::Service;
use hyper::Response;

struct MakeTestService;

Expand Down
6 changes: 3 additions & 3 deletions src/body.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// Helper methods to act on hyper::Body
/// Helper methods for processing body
use bytes::Bytes;
use futures::stream::{Stream, StreamExt};
use hyper::body::Bytes;

/// Additional function for hyper::Body
/// Additional function for converting body stream into Vec<u8>
pub trait BodyExt {
/// Raw body type
type Raw;
Expand Down
2 changes: 1 addition & 1 deletion src/composites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! Use by passing `hyper::server::MakeService` instances to a `CompositeMakeService`
//! together with the base path for requests that should be handled by that service.
use futures::future::{BoxFuture, FutureExt, TryFutureExt};
use http::{Request, Response, StatusCode};
use hyper::service::Service;
use hyper::{Request, Response, StatusCode};
use std::fmt;
use std::future::Future;
use std::net::SocketAddr;
Expand Down
22 changes: 11 additions & 11 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::XSpanIdString;
/// # use std::marker::PhantomData;
/// # use std::pin::Pin;
/// # use swagger::context::*;
/// # use hyper::body::Bytes;
/// # use bytes::Bytes;
/// # use http_body_util::Empty;
/// #
/// # struct MyItem;
Expand All @@ -29,17 +29,17 @@ use crate::XSpanIdString;
/// marker: PhantomData<C>,
/// }
///
/// impl<C, B> hyper::service::Service<(hyper::Request<B>, C)> for MyService<C>
/// impl<C, B> hyper::service::Service<(http::Request<B>, C)> for MyService<C>
/// where C: Has<MyItem> + Send + 'static
/// {
/// type Response = hyper::Response<Empty<Bytes>>;
/// type Response = http::Response<Empty<Bytes>>;
/// type Error = std::io::Error;
/// type Future = Pin<Box<dyn Future<Output=Result<Self::Response, Self::Error>>>>;
///
/// fn call(&self, req : (hyper::Request<B>, C)) -> Self::Future {
/// fn call(&self, req : (http::Request<B>, C)) -> Self::Future {
/// let (_, context) = req;
/// do_something_with_my_item(Has::<MyItem>::get(&context));
/// Box::pin(ok(hyper::Response::new(Empty::<Bytes>::new())))
/// Box::pin(ok(http::Response::new(Empty::<Bytes>::new())))
/// }
/// }
/// ```
Expand Down Expand Up @@ -70,19 +70,19 @@ pub trait Has<T> {
/// marker: PhantomData<C>,
/// }
///
/// impl<T, C, D, E, B> hyper::service::Service<(hyper::Request<B>, C)> for MiddlewareService<T, C>
/// impl<T, C, D, E, B> hyper::service::Service<(http::Request<B>, C)> for MiddlewareService<T, C>
/// where
/// C: Pop<MyItem1, Result=D> + Send + 'static,
/// D: Pop<MyItem2, Result=E>,
/// E: Pop<MyItem3>,
/// E::Result: Send + 'static,
/// T: hyper::service::Service<(hyper::Request<B>, E::Result)>
/// T: hyper::service::Service<(http::Request<B>, E::Result)>
/// {
/// type Response = T::Response;
/// type Error = T::Error;
/// type Future = T::Future;
///
/// fn call(&self, req : (hyper::Request<B>, C)) -> Self::Future {
/// fn call(&self, req : (http::Request<B>, C)) -> Self::Future {
/// let (request, context) = req;
///
/// // type annotations optional, included for illustrative purposes
Expand Down Expand Up @@ -118,19 +118,19 @@ pub trait Pop<T> {
/// marker: PhantomData<C>,
/// }
///
/// impl<T, C, D, E, B> hyper::service::Service<(hyper::Request<B>, C)> for MiddlewareService<T, C>
/// impl<T, C, D, E, B> hyper::service::Service<(http::Request<B>, C)> for MiddlewareService<T, C>
/// where
/// C: Push<MyItem1, Result=D> + Send + 'static,
/// D: Push<MyItem2, Result=E>,
/// E: Push<MyItem3>,
/// E::Result: Send + 'static,
/// T: hyper::service::Service<(hyper::Request<B>, E::Result)>
/// T: hyper::service::Service<(http::Request<B>, E::Result)>
/// {
/// type Response = T::Response;
/// type Error = T::Error;
/// type Future = T::Future;
///
/// fn call(&self, req : (hyper::Request<B>, C)) -> Self::Future {
/// fn call(&self, req : (http::Request<B>, C)) -> Self::Future {
/// let (request, context) = req;
/// let context = context
/// .push(MyItem1{})
Expand Down
14 changes: 7 additions & 7 deletions src/drop_context.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
//! Hyper service that drops a context to an incoming request and passes it on
//! to a wrapped service.

use hyper::Request;
use http::Request;
use std::marker::PhantomData;

use futures::future::FutureExt as _;

/// Middleware wrapper service that drops the context from the incoming request
/// and passes the plain `hyper::Request` to the wrapped service.
/// and passes the plain `http::Request` to the wrapped service.
///
/// This service can be used to to include services that take a plain `hyper::Request`
/// This service can be used to to include services that take a plain `http::Request`
/// in a `CompositeService` wrapped in an `AddContextService`.
///
/// Example Usage
/// =============
///
/// In the following example `SwaggerService` implements `hyper::service::MakeService`
/// with `Request = (hyper::Request, SomeContext)`, and `PlainService` implements it
/// with `Request = hyper::Request`
/// with `Request = (http::Request, SomeContext)`, and `PlainService` implements it
/// with `Request = http::Request`
///
/// ```ignore
/// let swagger_service_one = SwaggerService::new();
Expand Down Expand Up @@ -85,10 +85,10 @@ where
/// # use hyper_util::rt::TokioExecutor;
/// # use hyper_util::service::TowerToHyperService;
/// # use http_body_util::Empty;
/// # use hyper::body::Bytes;
/// # use bytes::Bytes;
/// let client = Client::builder(TokioExecutor::new()).build_http();
/// let client = DropContextService::new(TowerToHyperService::new(client));
/// let request = (hyper::Request::get("http://www.google.com").body(Empty::<Bytes>::new()).unwrap());
/// let request = (http::Request::get("http://www.google.com").body(Empty::<Bytes>::new()).unwrap());
/// let context = "Some Context".to_string();
///
/// let response = client.call((request, context));
Expand Down
2 changes: 1 addition & 1 deletion src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct XSpanIdString(pub String);
impl XSpanIdString {
/// Extract an X-Span-ID from a request header if present, and if not
/// generate a new one.
pub fn get_or_generate<T>(req: &hyper::Request<T>) -> Self {
pub fn get_or_generate<T>(req: &http::Request<T>) -> Self {
let x_span_id = req.headers().get(X_SPAN_ID);

x_span_id
Expand Down
2 changes: 1 addition & 1 deletion src/multipart/form.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Helper functions for multipart/form-data support
use hyper::header::{HeaderMap, CONTENT_TYPE};
use http::header::{HeaderMap, CONTENT_TYPE};

/// Utility function to get the multipart boundary marker (if any) from the Headers.
pub fn boundary(headers: &HeaderMap) -> Option<String> {
Expand Down
21 changes: 7 additions & 14 deletions src/multipart/related.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Helper functions for multipart/related support

use hyper::header::{HeaderValue, CONTENT_TYPE};
use hyper::HeaderMap;
use http::header::{HeaderValue, CONTENT_TYPE};
use http::HeaderMap;
use mime::Mime;

/// Construct the Body for a multipart/related request. The mime 0.2.6 library
Expand Down Expand Up @@ -42,7 +42,6 @@ pub fn create_multipart_headers(content_type: Option<&HeaderValue>) -> Result<He
#[cfg(test)]
mod tests {
use super::*;
use hyper_10::header::Headers;
use mime_multipart::Node;

// Test that we can parse the body using read_multipart_body
Expand All @@ -53,20 +52,14 @@ mod tests {

let body: &[u8] =
b"--example\r\nContent-Type: text/plain\r\n\r\nHello, World!\r\n--example--";
// Map Headers to hyper_10::header::Headers
let mut old_headers: Headers = Headers::new();
headers.iter().for_each(|(h, v)| {
let name = h.to_string();
let value = v.as_bytes();
old_headers.append_raw(name, value.to_vec());
});
let res = mime_multipart::read_multipart_body(&mut &body[..], &old_headers, false);
let res = mime_multipart::read_multipart_body(&mut &body[..], &headers, false);
// Check our content types are valid
match res.unwrap().first().unwrap() {
Node::Part(h) => {
let res: mime_026::Mime = h.content_type().unwrap();
let mime: mime_026::Mime = "text/plain".parse().unwrap();
assert_eq!(res, mime);
assert_eq!(
h.headers.get(CONTENT_TYPE).unwrap(),
&HeaderValue::from_static("text/plain")
);
}
_ => panic!("Expected Node::Multipart"),
}
Expand Down
6 changes: 3 additions & 3 deletions src/request_parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Methods for retrieving swagger-related information from an HTTP request.
use hyper::Request;
use http::Request;

/// A macro for joining together two or more RequestParsers to create a struct that implements
/// RequestParser with a function parse_operation_id that matches hyper requests against the different
Expand Down Expand Up @@ -53,9 +53,9 @@ pub trait RequestParser<B> {
#[cfg(test)]
mod context_tests {
use super::*;
use bytes::Bytes;
use http::Uri;
use http_body_util::Full;
use hyper::body::Bytes;
use hyper::Uri;
use std::str::FromStr;
struct TestParser1;

Expand Down
Loading