Skip to content

Commit

Permalink
feat(http): add multipart for server
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarisW committed Oct 25, 2024
1 parent f0351e6 commit 45193d4
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions volo-http/src/server/utils/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ mod multipart_tests {

async fn run_handler<S>(service: S, port: u16)
where
S: Service<ServerContext, ServerRequest, Response=ServerResponse, Error=Infallible>
+ Send
+ Sync
+ 'static,
S: Service<ServerContext, ServerRequest, Response = ServerResponse, Error = Infallible>
+ Send
+ Sync
+ 'static,
{
let addr = Address::Ip(SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
Expand Down Expand Up @@ -324,27 +324,29 @@ mod multipart_tests {
Ok(())
}

let form = Form::new().part(
FIELD_NAME1,
reqwest::multipart::Part::bytes(BYTES)
.file_name(FILE_NAME1)
.mime_str(CONTENT_TYPE)
.unwrap()
.headers(reqwest::header::HeaderMap::from_iter([(
reqwest::header::HeaderName::from_static("foo1"),
reqwest::header::HeaderValue::from_static("bar1"),
)])),
).part(
FIELD_NAME2,
reqwest::multipart::Part::bytes(BYTES)
.file_name(FILE_NAME2)
.mime_str(CONTENT_TYPE)
.unwrap()
.headers(reqwest::header::HeaderMap::from_iter([(
reqwest::header::HeaderName::from_static("foo2"),
reqwest::header::HeaderValue::from_static("bar2"),
)])),
);
let form = Form::new()
.part(
FIELD_NAME1,
reqwest::multipart::Part::bytes(BYTES)
.file_name(FILE_NAME1)
.mime_str(CONTENT_TYPE)
.unwrap()
.headers(reqwest::header::HeaderMap::from_iter([(
reqwest::header::HeaderName::from_static("foo1"),
reqwest::header::HeaderValue::from_static("bar1"),
)])),
)
.part(
FIELD_NAME2,
reqwest::multipart::Part::bytes(BYTES)
.file_name(FILE_NAME2)
.mime_str(CONTENT_TYPE)
.unwrap()
.headers(reqwest::header::HeaderMap::from_iter([(
reqwest::header::HeaderName::from_static("foo2"),
reqwest::header::HeaderValue::from_static("bar2"),
)])),
);

run_handler(test_helpers::to_service(handler), 25242).await;

Expand Down

0 comments on commit 45193d4

Please sign in to comment.