]> git.puffer.fish Git - matthieu/nova.git/commitdiff
ignore headers that are not 'Bot' headers
authorMatthieuCoder <matthieu@matthieu-dev.xyz>
Wed, 4 Jan 2023 19:13:05 +0000 (23:13 +0400)
committerMatthieuCoder <matthieu@matthieu-dev.xyz>
Wed, 4 Jan 2023 19:13:05 +0000 (23:13 +0400)
exes/rest/src/handler.rs

index 3828154130427992af237130770da6431244dcc7..004f763e385ad7d50cb2f12402c8b67ce922d88a 100644 (file)
@@ -106,11 +106,21 @@ pub async fn handle_request(
     request.headers_mut().remove("proxy-connection");
     request.headers_mut().remove(TRANSFER_ENCODING);
     request.headers_mut().remove(UPGRADE);
-    request.headers_mut().remove(AUTHORIZATION);
-    request.headers_mut().append(
-        AUTHORIZATION,
-        HeaderValue::from_str(&format!("Bot {}", token))?,
-    );
+    
+    if let Some(auth) = request.headers_mut().get_mut(AUTHORIZATION) {
+        if auth
+            .to_str()
+            .expect("Failed to check header")
+            .starts_with("Bot")
+        {
+            *auth = HeaderValue::from_str(&format!("Bot {}", token))?;
+        }
+    } else {
+        request.headers_mut().insert(
+            AUTHORIZATION,
+            HeaderValue::from_str(&format!("Bot {}", token))?,
+        );
+    }
 
     let uri = match Uri::from_str(&uri_string) {
         Ok(uri) => uri,
@@ -139,7 +149,7 @@ pub async fn handle_request(
         "X-Upstream-Ms",
         HeaderValue::from_str(&upstream_time_took.as_millis().to_string()).unwrap(),
     );
-    
+
     let ratelimit_headers = resp
         .headers()
         .into_iter()