From 8e2224bc0f14a879ce2899dde532661674018c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 14 Jan 2022 10:43:40 +0100 Subject: [PATCH] xmpp: pass in headers for http upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- xmpp/src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index 7f0ee642..01103beb 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -7,7 +7,9 @@ #![deny(bare_trait_objects)] use futures::stream::StreamExt; -use reqwest::{Body as ReqwestBody, Client as ReqwestClient}; +use reqwest::{ + header::HeaderMap as ReqwestHeaderMap, Body as ReqwestBody, Client as ReqwestClient, +}; use std::cell::RefCell; use std::convert::TryFrom; use std::path::{Path, PathBuf}; @@ -20,7 +22,7 @@ use xmpp_parsers::{ caps::{compute_disco, hash_caps, Caps}, disco::{DiscoInfoQuery, DiscoInfoResult, Feature, Identity}, hashes::Algo, - http_upload::{SlotRequest, SlotResult}, + http_upload::{Header as HttpUploadHeader, SlotRequest, SlotResult}, iq::{Iq, IqType}, message::{Body, Message, MessageType}, muc::{ @@ -468,11 +470,23 @@ async fn handle_upload_result( if let Some((index, file)) = res { agent.uploads.remove(index); let slot = SlotResult::try_from(elem).unwrap(); + + let mut headers = ReqwestHeaderMap::new(); + for header in slot.put.headers { + let (attr, val) = match header { + HttpUploadHeader::Authorization(val) => ("Authorization", val), + HttpUploadHeader::Cookie(val) => ("Cookie", val), + HttpUploadHeader::Expires(val) => ("Expires", val), + }; + headers.insert(attr, val.parse().unwrap()); + } + let web = ReqwestClient::new(); let stream = FramedRead::new(File::open(file).await.unwrap(), BytesCodec::new()); let body = ReqwestBody::wrap_stream(stream); let res = web .put(slot.put.url.as_str()) + .headers(headers) .body(body) .send() .await