Skip to content

Uri Builder path change broke parsing and reconstructing the Uri with empty path #846

Description

@Niels-Be

Version

http v1.4.1

Platform

Linux 6.8.0-111-generic Ubuntu 24.04

Summary

Uri Builder path change broke parsing and reconstructing the Uri with empty path.
In example below the path returns empty string.

This used to work fine to sanitize/cleanup a provided Url string, which I think is a common pattern people use.

As Uri.path() always returns a string and not an Option<String> its not intuitive that this stops working.

Also what is a bit annoying is that this broke in a patch update version.
Took me a while to figure out that an auto update of this dependency broke this behavior.

Code Sample

    let uri = Uri::from_str("example.com")?;
    let final_uri = Uri::builder()
        .scheme(uri.scheme_str().unwrap_or("https"))
        .authority(uri.authority()?.as_str())
        .path_and_query(uri.path())
        .build();

Expected Behavior

In v1.4.0 this used to work.

final_uri = Ok(Uri(...))

Actual Behavior

Since v1.4.1 this fails now.

final_uri = Err(http::Error(InvalidUri(Empty)))

Additional Context

If this is just intended and works as designed then feel free to close this.

Workaround I needed to add:

    let path = if !path.starts_with("/") {
        "/".to_string() + path
    } else {
        path.to_string()
    };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions