Manually updated reqwest to 10.8 and url to 2.1

master
ranfdev 4 years ago committed by Paul Woolcock
parent a8cbfad68f
commit 83587a10d2
  1. 4
      Cargo.toml
  2. 2
      src/errors.rs
  3. 44
      src/lib.rs
  4. 2
      src/page.rs
  5. 27
      src/registration.rs

@ -16,12 +16,12 @@ envy = { version = "0.4.0", optional = true }
hyper-old-types = "0.11.0" hyper-old-types = "0.11.0"
isolang = { version = "1.0", features = ["serde_serialize"] } isolang = { version = "1.0", features = ["serde_serialize"] }
log = "0.4.6" 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 = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
serde_urlencoded = "0.6.1" serde_urlencoded = "0.6.1"
serde_qs = "0.6.0" serde_qs = "0.6.0"
url = "1" url = "2.1.1"
tap-reader = "1" tap-reader = "1"
toml = { version = "0.5.0", optional = true } toml = { version = "0.5.0", optional = true }
try_from = "0.3.2" try_from = "0.3.2"

@ -182,7 +182,7 @@ mod tests {
#[test] #[test]
fn from_http_error() { 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); let err: Error = Error::from(err);
assert_is!(err, Error::Http(..)); assert_is!(err, Error::Http(..));
} }

@ -73,7 +73,7 @@
use std::{borrow::Cow, io::BufRead, ops}; use std::{borrow::Cow, io::BufRead, ops};
use reqwest::{Client, RequestBuilder, Response}; use reqwest::blocking::{Client, RequestBuilder, Response};
use tap_reader::Tap; use tap_reader::Tap;
use tungstenite::client::AutoStream; use tungstenite::client::AutoStream;
@ -461,7 +461,10 @@ impl MastodonClient for Mastodon {
url.query_pairs_mut() url.query_pairs_mut()
.append_pair("access_token", &self.token) .append_pair("access_token", &self.token)
.append_pair("stream", "user"); .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() { let new_scheme = match url.scheme() {
"http" => "ws", "http" => "ws",
"https" => "wss", "https" => "wss",
@ -481,7 +484,10 @@ impl MastodonClient for Mastodon {
url.query_pairs_mut() url.query_pairs_mut()
.append_pair("access_token", &self.token) .append_pair("access_token", &self.token)
.append_pair("stream", "public"); .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() { let new_scheme = match url.scheme() {
"http" => "ws", "http" => "ws",
"https" => "wss", "https" => "wss",
@ -501,7 +507,10 @@ impl MastodonClient for Mastodon {
url.query_pairs_mut() url.query_pairs_mut()
.append_pair("access_token", &self.token) .append_pair("access_token", &self.token)
.append_pair("stream", "public:local"); .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() { let new_scheme = match url.scheme() {
"http" => "ws", "http" => "ws",
"https" => "wss", "https" => "wss",
@ -522,7 +531,10 @@ impl MastodonClient for Mastodon {
.append_pair("access_token", &self.token) .append_pair("access_token", &self.token)
.append_pair("stream", "hashtag") .append_pair("stream", "hashtag")
.append_pair("tag", 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() { let new_scheme = match url.scheme() {
"http" => "ws", "http" => "ws",
"https" => "wss", "https" => "wss",
@ -543,7 +555,10 @@ impl MastodonClient for Mastodon {
.append_pair("access_token", &self.token) .append_pair("access_token", &self.token)
.append_pair("stream", "hashtag:local") .append_pair("stream", "hashtag:local")
.append_pair("tag", 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() { let new_scheme = match url.scheme() {
"http" => "ws", "http" => "ws",
"https" => "wss", "https" => "wss",
@ -564,7 +579,10 @@ impl MastodonClient for Mastodon {
.append_pair("access_token", &self.token) .append_pair("access_token", &self.token)
.append_pair("stream", "list") .append_pair("stream", "list")
.append_pair("list", list_id); .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() { let new_scheme = match url.scheme() {
"http" => "ws", "http" => "ws",
"https" => "wss", "https" => "wss",
@ -584,7 +602,10 @@ impl MastodonClient for Mastodon {
url.query_pairs_mut() url.query_pairs_mut()
.append_pair("access_token", &self.token) .append_pair("access_token", &self.token)
.append_pair("stream", "direct"); .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() { let new_scheme = match url.scheme() {
"http" => "ws", "http" => "ws",
"https" => "wss", "https" => "wss",
@ -600,7 +621,7 @@ impl MastodonClient for Mastodon {
/// Equivalent to /api/v1/media /// Equivalent to /api/v1/media
fn media(&self, media_builder: MediaBuilder) -> Result<Attachment> { fn media(&self, media_builder: MediaBuilder) -> Result<Attachment> {
use reqwest::multipart::Form; use reqwest::blocking::multipart::Form;
let mut form_data = Form::new().file("file", media_builder.file.as_ref())?; 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<EventReader<WebSocket>> { pub fn streaming_public(&self) -> Result<EventReader<WebSocket>> {
let mut url: url::Url = self.route("/api/v1/streaming/public/local")?; let mut url: url::Url = self.route("/api/v1/streaming/public/local")?;
url.query_pairs_mut().append_pair("stream", "public"); 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() { let new_scheme = match url.scheme() {
"http" => "ws", "http" => "ws",
"https" => "wss", "https" => "wss",

@ -1,7 +1,7 @@
use super::{deserialise, Mastodon, Result}; use super::{deserialise, Mastodon, Result};
use crate::entities::itemsiter::ItemsIter; use crate::entities::itemsiter::ItemsIter;
use hyper_old_types::header::{parsing, Link, RelationType}; use hyper_old_types::header::{parsing, Link, RelationType};
use reqwest::{header::LINK, Response}; use reqwest::{blocking::Response, header::LINK};
use serde::Deserialize; use serde::Deserialize;
use url::Url; use url::Url;

@ -1,9 +1,8 @@
use std::borrow::Cow; use std::borrow::Cow;
use reqwest::{Client, RequestBuilder, Response}; use reqwest::blocking::{Client, RequestBuilder, Response};
use serde::Deserialize; use serde::Deserialize;
use try_from::TryInto; use try_from::TryInto;
use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
use crate::{ use crate::{
apps::{App, AppBuilder}, apps::{App, AppBuilder},
@ -289,22 +288,16 @@ impl Registered {
/// Returns the full url needed for authorisation. This needs to be opened /// Returns the full url needed for authorisation. This needs to be opened
/// in a browser. /// in a browser.
pub fn authorize_url(&self) -> Result<String> { pub fn authorize_url(&self) -> Result<String> {
let scopes = format!("{}", self.scopes); let mut url = url::Url::parse(&self.base)?.join("/oauth/authorize")?;
let scopes: String = utf8_percent_encode(&scopes, DEFAULT_ENCODE_SET).collect();
let url = if self.force_login { url.query_pairs_mut()
format!( .append_pair("client_id", &self.client_id)
"{}/oauth/authorize?client_id={}&redirect_uri={}&scope={}&force_login=true&\ .append_pair("redirect_uri", &self.redirect)
response_type=code", .append_pair("scope", &self.scopes.to_string())
self.base, self.client_id, self.redirect, scopes, .append_pair("response_type", "code")
) .append_pair("force_login", &self.force_login.to_string());
} else {
format!(
"{}/oauth/authorize?client_id={}&redirect_uri={}&scope={}&response_type=code",
self.base, self.client_id, self.redirect, scopes,
)
};
Ok(url) Ok(url.into_string())
} }
/// Create an access token from the client id, client secret, and code /// Create an access token from the client id, client secret, and code

Loading…
Cancel
Save