Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!--## Unreleased-->
## Unreleased

### Fixed

- A path in the base url (for example `https://proxy.example.com/resend`) is no longer dropped from requests

## [0.33.0] - 2026-09-28

Expand Down
48 changes: 43 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,12 @@ impl Config {

/// Constructs a new [`RequestBuilder`].
pub(crate) fn build(&self, method: Method, path: &str) -> RequestBuilder {
let path = self
.base_url
.join(path)
.expect("should be a valid API endpoint");
let mut url = self.base_url.clone();
let base_path = url.path().trim_end_matches('/').to_owned();
url.set_path(&format!("{}/{}", base_path, path.trim_start_matches('/')));

self.client
.request(method, path)
.request(method, url)
.bearer_auth(self.api_key.as_str())
.header(USER_AGENT, self.user_agent.as_str())
}
Expand Down Expand Up @@ -259,3 +258,42 @@ impl fmt::Debug for Config {
.finish_non_exhaustive()
}
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod test {
use super::*;

fn url_for(base_url: &str, path: &str) -> String {
let config = Config::builder("re_test")
.base_url(base_url.parse().unwrap())
.build();

config
.build(Method::GET, path)
.build()
.unwrap()
.url()
.to_string()
}

#[test]
fn base_url_without_path() {
assert_eq!(
url_for("https://api.resend.com", "/emails"),
"https://api.resend.com/emails"
);
}

#[test]
fn base_url_path_prefix_is_kept() {
assert_eq!(
url_for("https://proxy.example.com/resend", "/emails/abc"),
"https://proxy.example.com/resend/emails/abc"
);
assert_eq!(
url_for("https://proxy.example.com/resend/", "/emails/abc"),
"https://proxy.example.com/resend/emails/abc"
);
}
}