mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 09:38:22 +02:00
Remove duplicate dependencies (#3961)
* chore: Replace surf with reqwest Removes a lot of older, duplication versions of some dependencies (roughtly 90 dependencies removed in total) * chore: Remove syn 0.11 * chore: Remove unnecessary features from ptree Removes some more duplicate dependencies * cargo update * Ensure we run the fetch and post plugins on the tokio runtime * Fix clippy warning * fix: Github requires a user agent on requests Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
7fe05b8296
commit
1c1c58e802
@ -19,7 +19,8 @@ nu-protocol = { path="../nu-protocol", version = "0.36.1" }
|
||||
nu-source = { path="../nu-source", version = "0.36.1" }
|
||||
num-traits = "0.2.12"
|
||||
serde_json = "1.0.57"
|
||||
surf = "2.2.0"
|
||||
reqwest = "0.11"
|
||||
tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||
url = "2.1.1"
|
||||
|
||||
[features]
|
||||
|
@ -1,4 +1,3 @@
|
||||
use futures::executor::block_on;
|
||||
use nu_errors::ShellError;
|
||||
use nu_plugin::Plugin;
|
||||
use nu_protocol::{CallInfo, ReturnValue, Signature, SyntaxShape};
|
||||
@ -46,7 +45,8 @@ impl Plugin for Post {
|
||||
|
||||
fn begin_filter(&mut self, call_info: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
|
||||
self.setup(call_info)?;
|
||||
Ok(vec![block_on(post_helper(
|
||||
let runtime = tokio::runtime::Runtime::new()?;
|
||||
Ok(vec![runtime.block_on(post_helper(
|
||||
&self.path.clone().ok_or_else(|| {
|
||||
ShellError::labeled_error("expected a 'path'", "expected a 'path'", &self.tag)
|
||||
})?,
|
||||
|
@ -132,7 +132,7 @@ pub async fn post(
|
||||
value: UntaggedValue::Primitive(Primitive::String(body_str)),
|
||||
..
|
||||
} => {
|
||||
let mut s = surf::post(location).body(body_str.to_string());
|
||||
let mut s = http_client().post(location).body(body_str.to_string());
|
||||
if let Some(login) = login {
|
||||
s = s.header("Authorization", format!("Basic {}", login));
|
||||
}
|
||||
@ -143,28 +143,29 @@ pub async fn post(
|
||||
HeaderKind::ContentLength(cl) => s.header("Content-Length", cl),
|
||||
};
|
||||
}
|
||||
s.await
|
||||
|
||||
s.send().await
|
||||
}
|
||||
Value {
|
||||
value: UntaggedValue::Primitive(Primitive::Binary(b)),
|
||||
..
|
||||
} => {
|
||||
let mut s = surf::post(location).body(&b[..]);
|
||||
let mut s = http_client().post(location).body(Vec::from(&b[..]));
|
||||
if let Some(login) = login {
|
||||
s = s.header("Authorization", format!("Basic {}", login));
|
||||
}
|
||||
s.await
|
||||
s.send().await
|
||||
}
|
||||
Value { value, tag } => {
|
||||
match value_to_json_value(&value.clone().into_untagged_value()) {
|
||||
Ok(json_value) => match serde_json::to_string(&json_value) {
|
||||
Ok(result_string) => {
|
||||
let mut s = surf::post(location).body(result_string);
|
||||
let mut s = http_client().post(location).body(result_string);
|
||||
|
||||
if let Some(login) = login {
|
||||
s = s.header("Authorization", format!("Basic {}", login));
|
||||
}
|
||||
s.await
|
||||
s.send().await
|
||||
}
|
||||
_ => {
|
||||
return Err(ShellError::labeled_error(
|
||||
@ -185,9 +186,12 @@ pub async fn post(
|
||||
}
|
||||
};
|
||||
match response {
|
||||
Ok(mut r) => match r.header("content-type") {
|
||||
Ok(r) => match r.headers().get("content-type") {
|
||||
Some(content_type) => {
|
||||
let content_type = Mime::from_str(content_type.as_str()).map_err(|_| {
|
||||
let content_type = content_type.to_str().map_err(|e| {
|
||||
ShellError::labeled_error(e.to_string(), "MIME type were invalid", &tag)
|
||||
})?;
|
||||
let content_type = Mime::from_str(content_type).map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
format!("Unknown MIME type: {}", content_type),
|
||||
"unknown MIME type",
|
||||
@ -197,7 +201,7 @@ pub async fn post(
|
||||
match (content_type.type_(), content_type.subtype()) {
|
||||
(mime::APPLICATION, mime::XML) => Ok((
|
||||
Some("xml".to_string()),
|
||||
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||
UntaggedValue::string(r.text().await.map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not load text from remote url",
|
||||
"could not load",
|
||||
@ -211,7 +215,7 @@ pub async fn post(
|
||||
)),
|
||||
(mime::APPLICATION, mime::JSON) => Ok((
|
||||
Some("json".to_string()),
|
||||
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||
UntaggedValue::string(r.text().await.map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not load text from remote url",
|
||||
"could not load",
|
||||
@ -224,13 +228,17 @@ pub async fn post(
|
||||
},
|
||||
)),
|
||||
(mime::APPLICATION, mime::OCTET_STREAM) => {
|
||||
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not load binary file",
|
||||
"could not load",
|
||||
&tag,
|
||||
)
|
||||
})?;
|
||||
let buf: Vec<u8> = r
|
||||
.bytes()
|
||||
.await
|
||||
.map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not load binary file",
|
||||
"could not load",
|
||||
&tag,
|
||||
)
|
||||
})?
|
||||
.to_vec();
|
||||
Ok((
|
||||
None,
|
||||
UntaggedValue::binary(buf),
|
||||
@ -241,13 +249,17 @@ pub async fn post(
|
||||
))
|
||||
}
|
||||
(mime::IMAGE, image_ty) => {
|
||||
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not load image file",
|
||||
"could not load",
|
||||
&tag,
|
||||
)
|
||||
})?;
|
||||
let buf: Vec<u8> = r
|
||||
.bytes()
|
||||
.await
|
||||
.map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not load image file",
|
||||
"could not load",
|
||||
&tag,
|
||||
)
|
||||
})?
|
||||
.to_vec();
|
||||
Ok((
|
||||
Some(image_ty.to_string()),
|
||||
UntaggedValue::binary(buf),
|
||||
@ -259,7 +271,7 @@ pub async fn post(
|
||||
}
|
||||
(mime::TEXT, mime::HTML) => Ok((
|
||||
Some("html".to_string()),
|
||||
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||
UntaggedValue::string(r.text().await.map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not load text from remote url",
|
||||
"could not load",
|
||||
@ -291,7 +303,7 @@ pub async fn post(
|
||||
|
||||
Ok((
|
||||
path_extension,
|
||||
UntaggedValue::string(r.body_string().await.map_err(|_| {
|
||||
UntaggedValue::string(r.text().await.map_err(|_| {
|
||||
ShellError::labeled_error(
|
||||
"Could not load text from remote url",
|
||||
"could not load",
|
||||
@ -509,3 +521,13 @@ fn extract_header_value(call_info: &CallInfo, key: &str) -> Result<Option<String
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
// Only panics if the user agent is invalid but we define it statically so either
|
||||
// it always or never fails
|
||||
#[allow(clippy::unwrap_used)]
|
||||
fn http_client() -> reqwest::Client {
|
||||
reqwest::Client::builder()
|
||||
.user_agent("nushell")
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
|
Reference in New Issue
Block a user