Skip to content

Commit

Permalink
Merge pull request #41 from lsk569937453/dev
Browse files Browse the repository at this point in the history
Add the upload-file option.
  • Loading branch information
lsk569937453 authored Jun 7, 2024
2 parents d59ab4d + 846b0b4 commit 0a82e69
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Cargo.lock
*.pdb
.idea
*.profraw
*.html
*.html
.vscode
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rcurl"
version = "0.0.25"
version = "0.0.26"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ rcurl -A 'a:b' http://httpbin.org/get
```
rcurl -b 'a:b' http://httpbin.org/get
```
## Upload File
```
rcurl --upload-file .gitignore http://httpbin.org/put
```
## Http2
### Default
```
Expand Down
6 changes: 6 additions & 0 deletions src/http/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ pub async fn http_request(
method = String::from("POST");
content_type_option = Some(String::from("application/x-www-form-urlencoded"));
}
if cli.uploadfile_option.is_some() {
method = String::from("PUT");
}
if let Some(method_userdefined) = cli.method_option.clone() {
method = method_userdefined;
}
Expand Down Expand Up @@ -287,6 +290,9 @@ pub async fn http_request(
body_bytes = bytes.into();
} else if let Some(body) = cli.body_option.clone() {
body_bytes = Bytes::from(body);
} else if let Some(upload_file) = cli.uploadfile_option.clone() {
let byte_vec = tokio::fs::read(upload_file).await?;
body_bytes = Bytes::from(byte_vec);
}

if cli.header_option {
Expand Down

0 comments on commit 0a82e69

Please sign in to comment.