Skip to content

Fix: follow redirect unicode#646

Merged
seanmonstar merged 6 commits intomainfrom
unknown repository
Feb 13, 2026
Merged

Fix: follow redirect unicode#646
seanmonstar merged 6 commits intomainfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Feb 10, 2026

Motivation

Hi there! I’m interested in helping out with #630.

I've swapped iri-string for url in the follow-redirect module as it seems to be the most robust way to handle non-ASCII characters in redirects. I'd appreciate any feedback on the approach.

Solution

  • Replaced iri-string with url crate in follow-redirect feature
  • Simplified resolve_uri() function implementation
  • Added tests for Unicode path and IDNA domain handling
  • Removed unused iri-string dependency

Testing

Added test_resolve_uri_unicode() that verifies:

  • Unicode characters in paths are percent-encoded correctly
  • International domain names are converted to punycode via IDNA

Copy link
Collaborator

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

catch-panic = ["tracing", "futures-util/std", "dep:http-body", "dep:http-body-util"]
cors = []
follow-redirect = ["futures-util", "dep:http-body", "iri-string", "tower/util"]
follow-redirect = ["futures-util", "dep:http-body", "url", "tower/util"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
follow-redirect = ["futures-util", "dep:http-body", "url", "tower/util"]
follow-redirect = ["futures-util", "dep:http-body", "dep:url", "tower/util"]

Uri::try_from(uri).ok()
let base_url = Url::parse(&base.to_string()).ok()?;
let resolved = base_url.join(relative).ok()?;
resolved.as_str().parse().ok()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resolved.as_str().parse().ok()
Uri::try_from(String::from(resolved)).ok()

(requires use std::convert::TryFrom; again)

parse incurs additional allocation.

@ghost
Copy link
Author

ghost commented Feb 11, 2026

I've updated the PR with the suggested changes: switched url to a dep: dependency in Cargo.toml and moved to Uri::try_from to avoid the extra allocation. Ready for another review when you have a moment!

Copy link
Collaborator

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@seanmonstar seanmonstar merged commit 0a2dd3d into tower-rs:main Feb 13, 2026
11 checks passed
@ghost ghost deleted the fix/follow-redirect-unicode branch February 15, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants