Merge branch 'duplicate-content-type-header'
commit
42fb88a7f9
|
@ -18,7 +18,7 @@ use std::{convert::TryFrom, fmt::Debug, sync::Arc};
|
||||||
use backoff::{future::retry, Error as RetryError, ExponentialBackoff};
|
use backoff::{future::retry, Error as RetryError, ExponentialBackoff};
|
||||||
#[cfg(all(not(test), not(target_arch = "wasm32")))]
|
#[cfg(all(not(test), not(target_arch = "wasm32")))]
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use http::{HeaderValue, Method as HttpMethod, Response as HttpResponse};
|
use http::{HeaderValue, Response as HttpResponse};
|
||||||
use reqwest::{Client, Response};
|
use reqwest::{Client, Response};
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -104,10 +104,9 @@ impl HttpClient {
|
||||||
&self,
|
&self,
|
||||||
request: Request,
|
request: Request,
|
||||||
session: Arc<RwLock<Option<Session>>>,
|
session: Arc<RwLock<Option<Session>>>,
|
||||||
content_type: Option<HeaderValue>,
|
|
||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
) -> Result<http::Response<Vec<u8>>, HttpError> {
|
) -> Result<http::Response<Vec<u8>>, HttpError> {
|
||||||
let mut request = {
|
let request = {
|
||||||
let read_guard;
|
let read_guard;
|
||||||
let access_token = match Request::METADATA.authentication {
|
let access_token = match Request::METADATA.authentication {
|
||||||
AuthScheme::AccessToken => {
|
AuthScheme::AccessToken => {
|
||||||
|
@ -126,14 +125,6 @@ impl HttpClient {
|
||||||
request.try_into_http_request(&self.homeserver.to_string(), access_token)?
|
request.try_into_http_request(&self.homeserver.to_string(), access_token)?
|
||||||
};
|
};
|
||||||
|
|
||||||
if let HttpMethod::POST | HttpMethod::PUT | HttpMethod::DELETE = *request.method() {
|
|
||||||
if let Some(content_type) = content_type {
|
|
||||||
request
|
|
||||||
.headers_mut()
|
|
||||||
.append(http::header::CONTENT_TYPE, content_type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.inner.send_request(request, timeout).await
|
self.inner.send_request(request, timeout).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +134,7 @@ impl HttpClient {
|
||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
) -> Result<create_content::Response, HttpError> {
|
) -> Result<create_content::Response, HttpError> {
|
||||||
let response = self
|
let response = self
|
||||||
.send_request(request, self.session.clone(), None, timeout)
|
.send_request(request, self.session.clone(), timeout)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(create_content::Response::try_from(response)?)
|
Ok(create_content::Response::try_from(response)?)
|
||||||
}
|
}
|
||||||
|
@ -157,9 +148,8 @@ impl HttpClient {
|
||||||
Request: OutgoingRequest + Debug,
|
Request: OutgoingRequest + Debug,
|
||||||
HttpError: From<FromHttpResponseError<Request::EndpointError>>,
|
HttpError: From<FromHttpResponseError<Request::EndpointError>>,
|
||||||
{
|
{
|
||||||
let content_type = HeaderValue::from_static("application/json");
|
|
||||||
let response = self
|
let response = self
|
||||||
.send_request(request, self.session.clone(), Some(content_type), timeout)
|
.send_request(request, self.session.clone(), timeout)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
trace!("Got response: {:?}", response);
|
trace!("Got response: {:?}", response);
|
||||||
|
|
Loading…
Reference in New Issue