Replaced ureq_multipart with multipart-rs

The latter seems maintained and does provide a license, unlike the
former.
This commit is contained in:
Bruce Weirdan 2024-08-04 02:03:44 +02:00
parent 0f6b2b214a
commit fc964074d3
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
4 changed files with 36 additions and 108 deletions

113
Cargo.lock generated
View File

@ -2748,6 +2748,20 @@ dependencies = [
"tokio",
]
[[package]]
name = "multipart-rs"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ea34e5c0fa65ba84707cfaf5bf43d500f1c5a4c6c36327bf5541c5bcd17e98"
dependencies = [
"bytes",
"futures-core",
"futures-util",
"memchr",
"mime",
"uuid",
]
[[package]]
name = "multiversion"
version = "0.7.4"
@ -2877,6 +2891,7 @@ dependencies = [
"log",
"miette",
"mimalloc",
"multipart-rs",
"nix",
"nu-cli",
"nu-cmd-base",
@ -2908,7 +2923,6 @@ dependencies = [
"tango-bench",
"tempfile",
"time",
"ureq_multipart",
"winresource",
]
@ -3065,6 +3079,7 @@ dependencies = [
"mime",
"mime_guess",
"mockito",
"multipart-rs",
"native-tls",
"nix",
"notify-debouncer-full",
@ -3122,7 +3137,6 @@ dependencies = [
"unicode-segmentation",
"unicode-width",
"ureq",
"ureq_multipart",
"url",
"uu_cp",
"uu_mkdir",
@ -5106,21 +5120,6 @@ dependencies = [
"thiserror",
]
[[package]]
name = "ring"
version = "0.17.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d"
dependencies = [
"cc",
"cfg-if",
"getrandom",
"libc",
"spin",
"untrusted",
"windows-sys 0.52.0",
]
[[package]]
name = "rkyv"
version = "0.7.44"
@ -5331,38 +5330,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "rustls"
version = "0.23.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044"
dependencies = [
"log",
"once_cell",
"ring",
"rustls-pki-types",
"rustls-webpki",
"subtle",
"zeroize",
]
[[package]]
name = "rustls-pki-types"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d"
[[package]]
name = "rustls-webpki"
version = "0.102.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e"
dependencies = [
"ring",
"rustls-pki-types",
"untrusted",
]
[[package]]
name = "rustversion"
version = "1.0.15"
@ -5786,12 +5753,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
[[package]]
name = "sqlparser"
version = "0.47.0"
@ -5926,12 +5887,6 @@ dependencies = [
"syn 2.0.60",
]
[[package]]
name = "subtle"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "supports-color"
version = "2.1.0"
@ -6543,12 +6498,6 @@ version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "ureq"
version = "2.10.0"
@ -6561,24 +6510,9 @@ dependencies = [
"log",
"native-tls",
"once_cell",
"rustls",
"rustls-pki-types",
"serde",
"serde_json",
"url",
"webpki-roots",
]
[[package]]
name = "ureq_multipart"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22baf2d124865fc4d505f5942222a57f6a3eae8a133819d7fd6194423e3f6e91"
dependencies = [
"mime",
"mime_guess",
"rand",
"ureq",
]
[[package]]
@ -6984,15 +6918,6 @@ dependencies = [
"url",
]
[[package]]
name = "webpki-roots"
version = "0.26.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd"
dependencies = [
"rustls-pki-types",
]
[[package]]
name = "which"
version = "6.0.1"
@ -7448,12 +7373,6 @@ dependencies = [
"syn 2.0.60",
]
[[package]]
name = "zeroize"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
[[package]]
name = "zip"
version = "0.6.6"

View File

@ -113,6 +113,7 @@ miette = "7.2"
mime = "0.3"
mime_guess = "2.0"
mockito = { version = "1.4", default-features = false }
multipart-rs = "0.1.11"
native-tls = "0.2"
nix = { version = "0.28", default-features = false }
notify-debouncer-full = { version = "0.3", default-features = false }
@ -166,7 +167,6 @@ umask = "2.1"
unicode-segmentation = "1.11"
unicode-width = "0.1"
ureq = { version = "2.10", default-features = false }
ureq_multipart = "1.1.1"
url = "2.2"
uu_cp = "0.0.27"
uu_mkdir = "0.0.27"
@ -208,10 +208,10 @@ dirs = { workspace = true }
log = { workspace = true }
miette = { workspace = true, features = ["fancy-no-backtrace", "fancy"] }
mimalloc = { version = "0.1.42", default-features = false, optional = true }
multipart-rs = { workspace = true }
serde_json = { workspace = true }
simplelog = "0.12"
time = "0.3"
ureq_multipart = { workspace = true }
[target.'cfg(not(target_os = "windows"))'.dependencies]
# Our dependencies don't use OpenSSL on Windows

View File

@ -60,6 +60,7 @@ lscolors = { workspace = true, default-features = false, features = ["nu-ansi-te
md5 = { workspace = true }
mime = { workspace = true }
mime_guess = { workspace = true }
multipart-rs = { workspace = true }
native-tls = { workspace = true }
notify-debouncer-full = { workspace = true, default-features = false }
num-format = { workspace = true }
@ -90,7 +91,6 @@ titlecase = { workspace = true }
toml = { workspace = true, features = ["preserve_order"]}
unicode-segmentation = { workspace = true }
ureq = { workspace = true, default-features = false, features = ["charset", "gzip", "json", "native-tls"] }
ureq_multipart = { workspace = true }
url = { workspace = true }
uu_cp = { workspace = true }
uu_mkdir = { workspace = true }

View File

@ -4,6 +4,7 @@ use base64::{
engine::{general_purpose::PAD, GeneralPurpose},
Engine,
};
use multipart_rs::MultipartWriter;
use nu_engine::command_prelude::*;
use nu_protocol::{ByteStream, Signals};
use std::{
@ -15,7 +16,6 @@ use std::{
time::Duration,
};
use ureq::{Error, ErrorKind, Request, Response};
use ureq_multipart::MultipartBuilder;
use url::Url;
#[derive(PartialEq, Eq)]
@ -271,7 +271,7 @@ pub fn send_request(
}
// multipart form upload
Value::Record { val, .. } if body_type == BodyType::Multipart => {
let mut builder = MultipartBuilder::new();
let mut builder = MultipartWriter::new();
let err = |e| {
ShellErrorOrRequestError::ShellError(ShellError::IOError {
@ -281,17 +281,26 @@ pub fn send_request(
for (col, val) in val.into_owned() {
if let Value::Binary { val, .. } = val {
builder = builder
.add_stream(&mut Cursor::new(val), &col, Some(&col), None)
.map_err(err)?;
let headers = format!(
r#"Content-Type: application/octet-stream
Content-Disposition: form-data; name="{}"; filename="{}"
Content-Transfer-Encoding: binary
"#,
col, col,
);
builder.add(&mut Cursor::new(val), &headers).map_err(err)?;
} else {
builder = builder
.add_text(&col, &val.coerce_into_string()?)
let headers =
format!(r#"Content-Disposition: form-data; name="{}""#, col,);
builder
.add(val.coerce_into_string()?.as_bytes(), &headers)
.map_err(err)?;
}
}
builder.finish();
let (content_type, data) = builder.finish().map_err(err)?;
let (boundary, data) = (builder.boundary, builder.data);
let content_type = format!("multipart/form-data; boundary={}", boundary);
let request_fn =
move || req.set("Content-Type", &content_type).send_bytes(&data);