From 83587a10d2c7667360b2846a0601df2bc48c9677 Mon Sep 17 00:00:00 2001 From: ranfdev Date: Sat, 26 Sep 2020 22:09:43 +0200 Subject: [PATCH] Manually updated reqwest to 10.8 and url to 2.1 --- Cargo.toml | 4 ++-- src/errors.rs | 2 +- src/lib.rs | 44 ++++++++++++++++++++++++++++++++++---------- src/page.rs | 2 +- src/registration.rs | 27 ++++++++++----------------- 5 files changed, 48 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e4e905b..82f7ce8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,12 +16,12 @@ envy = { version = "0.4.0", optional = true } hyper-old-types = "0.11.0" isolang = { version = "1.0", features = ["serde_serialize"] } log = "0.4.6" -reqwest = { version = "0.9", default-features = false } +reqwest = { version = "0.10.8", default-features = false, features = ["json", "blocking"] } serde = { version = "1", features = ["derive"] } serde_json = "1" serde_urlencoded = "0.6.1" serde_qs = "0.6.0" -url = "1" +url = "2.1.1" tap-reader = "1" toml = { version = "0.5.0", optional = true } try_from = "0.3.2" diff --git a/src/errors.rs b/src/errors.rs index 1e186df..2813bfd 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -182,7 +182,7 @@ mod tests { #[test] fn from_http_error() { - let err: HttpError = reqwest::get("not an actual URL").unwrap_err(); + let err: HttpError = reqwest::blocking::get("not an actual URL").unwrap_err(); let err: Error = Error::from(err); assert_is!(err, Error::Http(..)); } diff --git a/src/lib.rs b/src/lib.rs index ae08820..165c775 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ use std::{borrow::Cow, io::BufRead, ops}; -use reqwest::{Client, RequestBuilder, Response}; +use reqwest::blocking::{Client, RequestBuilder, Response}; use tap_reader::Tap; use tungstenite::client::AutoStream; @@ -461,7 +461,10 @@ impl MastodonClient for Mastodon { url.query_pairs_mut() .append_pair("access_token", &self.token) .append_pair("stream", "user"); - let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let mut url: url::Url = reqwest::blocking::get(url.as_str())? + .url() + .as_str() + .parse()?; let new_scheme = match url.scheme() { "http" => "ws", "https" => "wss", @@ -481,7 +484,10 @@ impl MastodonClient for Mastodon { url.query_pairs_mut() .append_pair("access_token", &self.token) .append_pair("stream", "public"); - let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let mut url: url::Url = reqwest::blocking::get(url.as_str())? + .url() + .as_str() + .parse()?; let new_scheme = match url.scheme() { "http" => "ws", "https" => "wss", @@ -501,7 +507,10 @@ impl MastodonClient for Mastodon { url.query_pairs_mut() .append_pair("access_token", &self.token) .append_pair("stream", "public:local"); - let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let mut url: url::Url = reqwest::blocking::get(url.as_str())? + .url() + .as_str() + .parse()?; let new_scheme = match url.scheme() { "http" => "ws", "https" => "wss", @@ -522,7 +531,10 @@ impl MastodonClient for Mastodon { .append_pair("access_token", &self.token) .append_pair("stream", "hashtag") .append_pair("tag", hashtag); - let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let mut url: url::Url = reqwest::blocking::get(url.as_str())? + .url() + .as_str() + .parse()?; let new_scheme = match url.scheme() { "http" => "ws", "https" => "wss", @@ -543,7 +555,10 @@ impl MastodonClient for Mastodon { .append_pair("access_token", &self.token) .append_pair("stream", "hashtag:local") .append_pair("tag", hashtag); - let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let mut url: url::Url = reqwest::blocking::get(url.as_str())? + .url() + .as_str() + .parse()?; let new_scheme = match url.scheme() { "http" => "ws", "https" => "wss", @@ -564,7 +579,10 @@ impl MastodonClient for Mastodon { .append_pair("access_token", &self.token) .append_pair("stream", "list") .append_pair("list", list_id); - let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let mut url: url::Url = reqwest::blocking::get(url.as_str())? + .url() + .as_str() + .parse()?; let new_scheme = match url.scheme() { "http" => "ws", "https" => "wss", @@ -584,7 +602,10 @@ impl MastodonClient for Mastodon { url.query_pairs_mut() .append_pair("access_token", &self.token) .append_pair("stream", "direct"); - let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let mut url: url::Url = reqwest::blocking::get(url.as_str())? + .url() + .as_str() + .parse()?; let new_scheme = match url.scheme() { "http" => "ws", "https" => "wss", @@ -600,7 +621,7 @@ impl MastodonClient for Mastodon { /// Equivalent to /api/v1/media fn media(&self, media_builder: MediaBuilder) -> Result { - use reqwest::multipart::Form; + use reqwest::blocking::multipart::Form; let mut form_data = Form::new().file("file", media_builder.file.as_ref())?; @@ -808,7 +829,10 @@ impl MastodonUnauth { pub fn streaming_public(&self) -> Result> { let mut url: url::Url = self.route("/api/v1/streaming/public/local")?; url.query_pairs_mut().append_pair("stream", "public"); - let mut url: url::Url = reqwest::get(url.as_str())?.url().as_str().parse()?; + let mut url: url::Url = reqwest::blocking::get(url.as_str())? + .url() + .as_str() + .parse()?; let new_scheme = match url.scheme() { "http" => "ws", "https" => "wss", diff --git a/src/page.rs b/src/page.rs index 057f6e8..a5efd56 100644 --- a/src/page.rs +++ b/src/page.rs @@ -1,7 +1,7 @@ use super::{deserialise, Mastodon, Result}; use crate::entities::itemsiter::ItemsIter; use hyper_old_types::header::{parsing, Link, RelationType}; -use reqwest::{header::LINK, Response}; +use reqwest::{blocking::Response, header::LINK}; use serde::Deserialize; use url::Url; diff --git a/src/registration.rs b/src/registration.rs index 32bac61..5379e87 100644 --- a/src/registration.rs +++ b/src/registration.rs @@ -1,9 +1,8 @@ use std::borrow::Cow; -use reqwest::{Client, RequestBuilder, Response}; +use reqwest::blocking::{Client, RequestBuilder, Response}; use serde::Deserialize; use try_from::TryInto; -use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET}; use crate::{ apps::{App, AppBuilder}, @@ -289,22 +288,16 @@ impl Registered { /// Returns the full url needed for authorisation. This needs to be opened /// in a browser. pub fn authorize_url(&self) -> Result { - let scopes = format!("{}", self.scopes); - let scopes: String = utf8_percent_encode(&scopes, DEFAULT_ENCODE_SET).collect(); - let url = if self.force_login { - format!( - "{}/oauth/authorize?client_id={}&redirect_uri={}&scope={}&force_login=true&\ - response_type=code", - self.base, self.client_id, self.redirect, scopes, - ) - } else { - format!( - "{}/oauth/authorize?client_id={}&redirect_uri={}&scope={}&response_type=code", - self.base, self.client_id, self.redirect, scopes, - ) - }; + let mut url = url::Url::parse(&self.base)?.join("/oauth/authorize")?; + + url.query_pairs_mut() + .append_pair("client_id", &self.client_id) + .append_pair("redirect_uri", &self.redirect) + .append_pair("scope", &self.scopes.to_string()) + .append_pair("response_type", "code") + .append_pair("force_login", &self.force_login.to_string()); - Ok(url) + Ok(url.into_string()) } /// Create an access token from the client id, client secret, and code