upgrade to ureq 2.0
Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
parent
5ca86af0aa
commit
8afb9d2391
|
@ -596,70 +596,6 @@ version = "0.6.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a68a4904193147e0a8dec3314640e6db742afd5f6e634f428a6af230d9b3591"
|
||||
|
||||
[[package]]
|
||||
name = "encoding"
|
||||
version = "0.2.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
|
||||
dependencies = [
|
||||
"encoding-index-japanese",
|
||||
"encoding-index-korean",
|
||||
"encoding-index-simpchinese",
|
||||
"encoding-index-singlebyte",
|
||||
"encoding-index-tradchinese",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-japanese"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-korean"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-simpchinese"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-singlebyte"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding-index-tradchinese"
|
||||
version = "1.20141219.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
|
||||
dependencies = [
|
||||
"encoding_index_tests",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_index_tests"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.26"
|
||||
|
@ -1275,7 +1211,7 @@ dependencies = [
|
|||
"tracing-log",
|
||||
"tracing-subscriber",
|
||||
"twapi-ureq",
|
||||
"ureq",
|
||||
"ureq 2.0.0",
|
||||
"url 2.1.1",
|
||||
]
|
||||
|
||||
|
@ -2220,6 +2156,19 @@ dependencies = [
|
|||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"log 0.4.11",
|
||||
"ring",
|
||||
"sct",
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusty_ulid"
|
||||
version = "0.10.0"
|
||||
|
@ -2876,7 +2825,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"twapi-oauth",
|
||||
"ureq",
|
||||
"ureq 1.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2981,16 +2930,34 @@ dependencies = [
|
|||
"chunked_transfer",
|
||||
"cookie 0.14.2",
|
||||
"cookie_store",
|
||||
"encoding",
|
||||
"log 0.4.11",
|
||||
"once_cell",
|
||||
"qstring",
|
||||
"rustls",
|
||||
"rustls 0.18.1",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url 2.1.1",
|
||||
"webpki",
|
||||
"webpki-roots",
|
||||
"webpki-roots 0.20.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ureq"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e562326b32e3766fee6a4890b62489b4b095e94ac07232cfea631668002c19d7"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"chunked_transfer",
|
||||
"encoding_rs",
|
||||
"log 0.4.11",
|
||||
"once_cell",
|
||||
"rustls 0.19.0",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url 2.1.1",
|
||||
"webpki",
|
||||
"webpki-roots 0.21.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3145,6 +3112,15 @@ dependencies = [
|
|||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "82015b7e0b8bad8185994674a13a93306bea76cf5a16c5a181382fd3a5ec2376"
|
||||
dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
|
|
|
@ -36,7 +36,7 @@ tracing = "0.1"
|
|||
tracing-log = "0.1"
|
||||
tracing-subscriber = "0.2"
|
||||
twapi-ureq = "0.1.5"
|
||||
ureq = { version = "1", features = ["json", "charset"] }
|
||||
ureq = { version = "2", features = ["json", "charset"] }
|
||||
url = "2"
|
||||
|
||||
[dependencies.askama]
|
||||
|
|
|
@ -97,6 +97,12 @@ pub enum Error {
|
|||
|
||||
#[error("readability error: {0}")]
|
||||
Readability(#[from] readability_fork::error::Error),
|
||||
|
||||
#[error("ureq error: {0}")]
|
||||
UReq(#[from] ureq::Error),
|
||||
|
||||
#[error("futures error: {0}")]
|
||||
Futures(#[from] futures_io::Error),
|
||||
}
|
||||
|
||||
pub type Result<T = ()> = std::result::Result<T, Error>;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::Result;
|
||||
use crate::{
|
||||
models, paseto, schema,
|
||||
web::{DiscordWebhook, Error as WebError, Mastodon, Result as WebResult, Twitter},
|
||||
web::{DiscordWebhook, Mastodon, Result as WebResult, Twitter},
|
||||
MainDatabase,
|
||||
};
|
||||
use diesel::prelude::*;
|
||||
|
@ -55,16 +55,9 @@ impl Into<models::Blogpost> for Item {
|
|||
pub fn read_jsonfeed(url: String) -> WebResult<Jsonfeed> {
|
||||
let resp = ureq::get(&url)
|
||||
.set("User-Agent", crate::APPLICATION_NAME)
|
||||
.call();
|
||||
.call()?;
|
||||
|
||||
if resp.ok() {
|
||||
Ok(resp.into_json_deserialize()?)
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => WebError::UReq(why.to_string()),
|
||||
None => WebError::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
Ok(resp.into_json()?)
|
||||
}
|
||||
|
||||
#[instrument(skip(dw, tw, ma), err)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::{Error, Result};
|
||||
use crate::{
|
||||
models, paseto, schema,
|
||||
web::{self, discord_webhook::Client as DiscordWebhook},
|
||||
web::{self, discord_webhook::Client as DiscordWebhook, Error as WebError},
|
||||
MainDatabase,
|
||||
};
|
||||
use diesel::prelude::*;
|
||||
|
@ -60,9 +60,8 @@ impl WebMention {
|
|||
let resp = ureq::get(&self.source)
|
||||
.set("User-Agent", crate::APPLICATION_NAME)
|
||||
.set("Mi-Mentioned-Url", &self.target)
|
||||
.call();
|
||||
.call()?;
|
||||
|
||||
if resp.ok() {
|
||||
let body = resp
|
||||
.into_string()
|
||||
.map_err(|why| Error::Web(web::Error::FuturesIO(why)))?;
|
||||
|
@ -70,12 +69,6 @@ impl WebMention {
|
|||
&mut body.as_bytes(),
|
||||
&url::Url::parse(&self.source)?,
|
||||
)?)
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::Web(web::Error::UReq(why.to_string())),
|
||||
None => Error::Web(web::Error::HttpStatus(resp.status())),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,12 +224,11 @@ pub fn bridgy_expand(conn: MainDatabase, wm: models::WebMention) -> Result {
|
|||
let resp = ureq::get(&wm.source_url)
|
||||
.set("User-Agent", crate::APPLICATION_NAME)
|
||||
.set("Mi-Mentioned-Url", &wm.target_url)
|
||||
.call();
|
||||
.call()
|
||||
.map_err(WebError::UReq)?;
|
||||
|
||||
if resp.ok() {
|
||||
let body = resp.into_string().unwrap();
|
||||
let body: String = resp.into_string()?;
|
||||
let result = parse(&body).unwrap().unwrap();
|
||||
debug!("{:?}", result);
|
||||
|
||||
diesel::update(webmentions.find(wm.id))
|
||||
.set(&models::UpdateWebMentionSource {
|
||||
|
@ -246,10 +238,4 @@ pub fn bridgy_expand(conn: MainDatabase, wm: models::WebMention) -> Result {
|
|||
.map_err(Error::Database)
|
||||
.unwrap();
|
||||
Ok(())
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::Web(web::Error::UReq(why.to_string())),
|
||||
None => Error::Web(web::Error::HttpStatus(resp.status())),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,13 @@ fn main() -> Result<()> {
|
|||
let resp = ureq::get(&wm.source_url)
|
||||
.set("User-Agent", crate::APPLICATION_NAME)
|
||||
.set("Mi-Mentioned-Url", &wm.target_url)
|
||||
.call();
|
||||
.call()
|
||||
.map_err(|why| {
|
||||
error!("can't fetch {}: {}", wm.source_url, why);
|
||||
why
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
if resp.ok() {
|
||||
let body = resp.into_string().unwrap();
|
||||
let result = parse(&body).unwrap().unwrap();
|
||||
info!("{:?}", result);
|
||||
|
@ -44,16 +48,6 @@ fn main() -> Result<()> {
|
|||
})
|
||||
.execute(&conn)
|
||||
.unwrap();
|
||||
} else {
|
||||
error!(
|
||||
"can't fetch {}: {}",
|
||||
wm.source_url,
|
||||
match resp.synthetic_error() {
|
||||
Some(why) => web::Error::UReq(why.to_string()),
|
||||
None => web::Error::HttpStatus(resp.status()),
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -17,17 +17,13 @@ fn main() -> Result<()> {
|
|||
|
||||
info!("{} weather importer starting up", mi::APPLICATION_NAME);
|
||||
|
||||
let resp = ureq::get(WEATHER_URL).set("User-Agent", WEATHER_URL).call();
|
||||
|
||||
if !resp.ok() {
|
||||
panic!(
|
||||
"{}",
|
||||
match resp.synthetic_error() {
|
||||
Some(why) => why.to_string(),
|
||||
None => resp.status_line().to_string(),
|
||||
}
|
||||
);
|
||||
}
|
||||
let resp = ureq::get(WEATHER_URL)
|
||||
.set("User-Agent", WEATHER_URL)
|
||||
.call()
|
||||
.map_err(|why| {
|
||||
panic!("{}", why.to_string());
|
||||
why
|
||||
})?;
|
||||
|
||||
let fin = DecodeReaderBytesBuilder::new()
|
||||
.encoding(Some(WINDOWS_1252))
|
||||
|
|
|
@ -3,7 +3,8 @@ access logs. If this program is doing something you don't want it to do,
|
|||
please contact me at me@christine.website.
|
||||
|
||||
This service is intended to act as a POSSE[1] syndication server for
|
||||
various services to various other services.
|
||||
various services to various other services. It also performs a lot of
|
||||
personal integrations between my data and cloud services.
|
||||
|
||||
Every effort is being taken to ensure that the data going through this
|
||||
server is my own.
|
||||
|
|
|
@ -45,17 +45,11 @@ impl Client {
|
|||
|
||||
#[instrument(skip(self), err)]
|
||||
pub fn send(&self, body: String) -> Result<()> {
|
||||
let resp = ureq::post(&self.webhook_url)
|
||||
ureq::post(&self.webhook_url)
|
||||
.set("User-Agent", crate::APPLICATION_NAME)
|
||||
.send_json(serde_json::to_value(Body::new(body))?);
|
||||
.send_json(serde_json::to_value(Body::new(body))?)
|
||||
.map_err(Error::UReq)?;
|
||||
|
||||
if resp.ok() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::UReq(why.to_string()),
|
||||
None => Error::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,18 +33,12 @@ impl Client {
|
|||
pub fn toot(&self, body: String) -> Result {
|
||||
let url = &format!("{}/api/v1/statuses", self.instance_url);
|
||||
|
||||
let resp = ureq::post(url)
|
||||
ureq::post(url)
|
||||
.set("Authorization", &format!("bearer {}", self.token))
|
||||
.set("User-Agent", crate::APPLICATION_NAME)
|
||||
.send_form(&[("status", body.as_str())]);
|
||||
.send_form(&[("status", body.as_str())])
|
||||
.map_err(Error::UReq)?;
|
||||
|
||||
if resp.ok() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::UReq(why.to_string()),
|
||||
None => Error::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,10 @@ pub enum Error {
|
|||
Serde(#[from] serde_json::Error),
|
||||
|
||||
#[error("ureq error: {0}")]
|
||||
UReq(String),
|
||||
UReq(#[from] ureq::Error),
|
||||
|
||||
#[error("old ureq error: {0}")]
|
||||
OldUReq(String),
|
||||
|
||||
#[error("http unsuccessful: {0}")]
|
||||
HttpStatus(u16),
|
||||
|
|
|
@ -99,14 +99,8 @@ pub fn get(tracking_number: String) -> Result<Info> {
|
|||
.set("Cache-Control", "max-age=0")
|
||||
.send_json(serde_json::to_value(PostBody {
|
||||
tracking_numbers: vec![tracking_number],
|
||||
})?);
|
||||
})?)
|
||||
.map_err(Error::UReq)?;
|
||||
|
||||
if resp.ok() {
|
||||
Ok(resp.into_json_deserialize()?)
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::UReq(why.to_string()),
|
||||
None => Error::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
Ok(resp.into_json()?)
|
||||
}
|
||||
|
|
|
@ -75,18 +75,10 @@ impl Client {
|
|||
))
|
||||
.set("Authorization", &self.api_token)
|
||||
.set("User-Agent", crate::APPLICATION_NAME)
|
||||
.call();
|
||||
.call()
|
||||
.map_err(Error::UReq)?;
|
||||
|
||||
debug!("headers: {:?}", resp.headers_names());
|
||||
|
||||
if resp.ok() {
|
||||
Ok(resp.into_json_deserialize()?)
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::UReq(why.to_string()),
|
||||
None => Error::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
Ok(resp.into_json()?)
|
||||
}
|
||||
|
||||
#[instrument(err, skip(self))]
|
||||
|
@ -97,20 +89,14 @@ impl Client {
|
|||
.ok_or_else(|| Error::SystemmateMappingNotFound(member_name.clone()))?
|
||||
.clone();
|
||||
|
||||
let resp = ureq::post("https://api.pluralkit.me/v1/s/switches")
|
||||
ureq::post("https://api.pluralkit.me/v1/s/switches")
|
||||
.set("Authorization", &self.api_token)
|
||||
.set("User-Agent", crate::APPLICATION_NAME)
|
||||
.send_json(serde_json::to_value(SwitchRequest {
|
||||
members: vec![member],
|
||||
})?);
|
||||
})?)
|
||||
.map_err(Error::UReq)?;
|
||||
|
||||
if resp.ok() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::UReq(why.to_string()),
|
||||
None => Error::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,21 +52,13 @@ impl Client {
|
|||
pub webhook: FrontAsk,
|
||||
}
|
||||
|
||||
let resp = ureq::post(&self.webhook_url).send_json(serde_json::to_value(Wrapper {
|
||||
let resp = ureq::post(&self.webhook_url)
|
||||
.send_json(serde_json::to_value(Wrapper {
|
||||
webhook: FrontAsk::default(),
|
||||
})?);
|
||||
})?)
|
||||
.map_err(Error::UReq)?;
|
||||
|
||||
if resp.ok() {
|
||||
Ok(resp.into_json_deserialize()?)
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => {
|
||||
error!("ureq error: {}", why);
|
||||
Error::UReq(why.to_string())
|
||||
}
|
||||
None => Error::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
Ok(resp.into_json()?)
|
||||
}
|
||||
|
||||
#[instrument(err, skip(self))]
|
||||
|
@ -76,20 +68,15 @@ impl Client {
|
|||
pub webhook: SwitchCommand,
|
||||
}
|
||||
|
||||
let resp = ureq::post(&self.webhook_url).send_json(serde_json::to_value(Wrapper {
|
||||
let resp = ureq::post(&self.webhook_url)
|
||||
.send_json(serde_json::to_value(Wrapper {
|
||||
webhook: SwitchCommand {
|
||||
command: "switch".to_string(),
|
||||
member_name: member_name,
|
||||
},
|
||||
})?);
|
||||
})?)
|
||||
.map_err(Error::UReq)?;
|
||||
|
||||
if resp.ok() {
|
||||
Ok(resp.into_json_deserialize()?)
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::UReq(why.to_string()),
|
||||
None => Error::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
Ok(resp.into_json()?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ impl Client {
|
|||
Ok(())
|
||||
} else {
|
||||
Err(match resp.synthetic_error() {
|
||||
Some(why) => Error::UReq(why.to_string()),
|
||||
Some(why) => Error::OldUReq(why.to_string()),
|
||||
None => Error::HttpStatus(resp.status()),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue