Skip to content

Commit

Permalink
Use HTTPS Connector with remaining HTTP functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Roughsketch authored and Zeyla Hellyer committed Jun 14, 2017
1 parent 2845681 commit 0d218e0
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ pub fn delete_webhook(webhook_id: u64) -> Result<()> {
///
/// [`Webhook`]: ../model/struct.Webhook.html
pub fn delete_webhook_with_token(webhook_id: u64, token: &str) -> Result<()> {
let client = HyperClient::new();
let client = request_client!();

verify(204, retry(|| client
.delete(&format!(api!("/webhooks/{}/{}"), webhook_id, token)))
.map_err(Error::Hyper)?)
Expand Down Expand Up @@ -750,7 +751,8 @@ pub fn edit_webhook(webhook_id: u64, map: &Value) -> Result<Webhook> {
/// [`edit_webhook`]: fn.edit_webhook.html
pub fn edit_webhook_with_token(webhook_id: u64, token: &str, map: &JsonMap) -> Result<Webhook> {
let body = serde_json::to_string(map)?;
let client = HyperClient::new();
let client = request_client!();

let response = retry(|| client
.patch(&format!(api!("/webhooks/{}/{}"), webhook_id, token))
.body(&body))
Expand Down Expand Up @@ -815,7 +817,8 @@ pub fn edit_webhook_with_token(webhook_id: u64, token: &str, map: &JsonMap) -> R
/// [Discord docs]: https://discordapp.com/developers/docs/resources/webhook#querystring-params
pub fn execute_webhook(webhook_id: u64, token: &str, map: &JsonMap) -> Result<Message> {
let body = serde_json::to_string(map)?;
let client = HyperClient::new();
let client = request_client!();

let response = retry(|| client
.post(&format!(api!("/webhooks/{}/{}"), webhook_id, token))
.body(&body))
Expand All @@ -828,7 +831,8 @@ pub fn execute_webhook(webhook_id: u64, token: &str, map: &JsonMap) -> Result<Me
///
/// Does not require authentication.
pub fn get_active_maintenances() -> Result<Vec<Maintenance>> {
let client = HyperClient::new();
let client = request_client!();

let response = retry(|| client.get(
status!("/scheduled-maintenances/active.json")))?;

Expand Down Expand Up @@ -1197,7 +1201,8 @@ pub fn get_messages(channel_id: u64, query: &str)
let url = format!(api!("/channels/{}/messages{}"),
channel_id,
query);
let client = HyperClient::new();
let client = request_client!();

let response = request(Route::ChannelsIdMessages(channel_id),
|| client.get(&url))?;

Expand Down Expand Up @@ -1243,7 +1248,8 @@ pub fn get_reaction_users(channel_id: u64,
///
/// Does not require authentication.
pub fn get_unresolved_incidents() -> Result<Vec<Incident>> {
let client = HyperClient::new();
let client = request_client!();

let response = retry(|| client.get(
status!("/incidents/unresolved.json")))?;

Expand All @@ -1259,7 +1265,8 @@ pub fn get_unresolved_incidents() -> Result<Vec<Incident>> {
///
/// Does not require authentication.
pub fn get_upcoming_maintenances() -> Result<Vec<Maintenance>> {
let client = HyperClient::new();
let client = request_client!();

let response = retry(|| client.get(
status!("/scheduled-maintenances/upcoming.json")))?;

Expand Down Expand Up @@ -1333,7 +1340,8 @@ pub fn get_webhook(webhook_id: u64) -> Result<Webhook> {
/// .expect("Error getting webhook");
/// ```
pub fn get_webhook_with_token(webhook_id: u64, token: &str) -> Result<Webhook> {
let client = HyperClient::new();
let client = request_client!();

let response = retry(|| client
.get(&format!(api!("/webhooks/{}/{}"), webhook_id, token)))
.map_err(Error::Hyper)?;
Expand Down Expand Up @@ -1392,7 +1400,10 @@ pub fn send_file<R: Read>(channel_id: u64, mut file: R, filename: &str, map: Jso
Err(_) => return Err(Error::Url(uri)),
};

let mut request = Request::new(Method::Post, url)?;
let tc = NativeTlsClient::new()?;
let connector = HttpsConnector::new(tc);
let mut request = Request::with_connector(Method::Post, url, &connector)?;

request.headers_mut()
.set(header::Authorization(TOKEN.lock().unwrap().clone()));
request.headers_mut()
Expand Down

0 comments on commit 0d218e0

Please sign in to comment.