Skip to content

Commit

Permalink
Prevent double slashes with HTTP proxy (serenity-rs#2377)
Browse files Browse the repository at this point in the history
Fixes serenity-rs#2322

Probably wouldn't have caused because double slashes are treated by HTTP
servers as single slashes in my experience.

After a bit of back and forth I opted not to use reqwest methods. Parsing the
given proxy in `HttpBuilder` into an `Url` directly means the builder method
returns `Result` (or panics) which is both ugly. Also, `Url`'s methods yield the
scheme and domain both as `&str`, so we would still just have a string in the
internal proxy field instead of a type-safe value. So I kept the current simple
solution that gets the job done and just added the fix.
  • Loading branch information
kangalio authored and mkrasnitski committed May 18, 2023
1 parent da4ffee commit 008a95e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ impl<'a> Request<'a> {
let mut path = self.route.path().to_string();

if let Some(proxy) = proxy {
path = path.replace("https://discord.com", proxy);
// trim_end_matches to prevent double slashes after the domain
path = path.replace("https://discord.com", proxy.trim_end_matches('/'));
}

if let Some(params) = self.params {
Expand Down

0 comments on commit 008a95e

Please sign in to comment.