aboutsummaryrefslogtreecommitdiff
path: root/src/https.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/https.rs')
-rw-r--r--src/https.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/https.rs b/src/https.rs
index 83eca7c..7dcf051 100644
--- a/src/https.rs
+++ b/src/https.rs
@@ -194,25 +194,24 @@ async fn handle(
handle_error(reverse_proxy::call(remote_addr.ip(), &to_addr, req).await)
};
- // Do further processing (compression, additionnal headers) only for 2xx responses
- if !response.status().is_success() {
- return Ok(response);
+ if response.status().is_success() {
+ // (TODO: maybe we want to add these headers even if it's not a success?)
+ for (header, value) in proxy_to.add_headers.iter() {
+ response.headers_mut().insert(
+ HeaderName::from_bytes(header.as_bytes())?,
+ HeaderValue::from_str(value)?,
+ );
+ }
}
- for (header, value) in proxy_to.add_headers.iter() {
- response.headers_mut().insert(
- HeaderName::from_bytes(header.as_bytes())?,
- HeaderValue::from_str(value)?,
- );
- }
- trace!("Response: {:?}", response);
- info!("{} {} {}", method, response.status().as_u16(), uri);
-
if https_config.enable_compression {
- try_compress(response, method, accept_encoding, &https_config).await
- } else {
- Ok(response)
- }
+ response =
+ try_compress(response, method.clone(), accept_encoding, &https_config).await?
+ };
+
+ trace!("Final response: {:?}", response);
+ info!("{} {} {}", method, response.status().as_u16(), uri);
+ Ok(response)
} else {
debug!("{}{} -> NOT FOUND", host, path);
info!("{} 404 {}", method, uri);
@@ -240,10 +239,14 @@ async fn try_compress(
https_config: &HttpsConfig,
) -> Result<Response<Body>> {
// Don't bother compressing successfull responses for HEAD and PUT (they should have an empty body)
- // Don't compress partial content, that would be wierd
- // If already compressed, return as is
+ // Don't compress partial content as it causes issues
+ // Don't bother compressing non-2xx results
+ // Don't compress Upgrade responses (e.g. websockets)
+ // Don't compress responses that are already compressed
if (response.status().is_success() && (method == Method::HEAD || method == Method::PUT))
|| response.status() == StatusCode::PARTIAL_CONTENT
+ || !response.status().is_success()
+ || response.headers().get(header::CONNECTION) == Some(&HeaderValue::from_static("Upgrade"))
|| response.headers().get(header::CONTENT_ENCODING).is_some()
{
return Ok(response);