Skip to content

There should be an uri::Builder #206

Open
@SergejJurecko

Description

@SergejJurecko

Right now the burden of correct percent encoding is entirely on the user. This is completely unnecessary. Only accepting string URI also forces users to concatenate strings to construct an URI, which is bad and inefficient practice that leads to bugs.

Examples

Entirely segmented

Uri::builder()
        .https()    // In mio_httpc I have both https() and set_https(true).
        .host("www.example.com")
        .auth("user name", "my password")
        .port(12345)
        .path_segm("a/")
        .path_segm("b")
        .query("spaced key", "123")
        .query("key", "<>")

Only partly segmented because schemes, hosts and optional ports are not a percent encoding problem and often stored as a fixed string on a client.

Uri::builder()
        .base("https://www.example.com:8080")?
        .path_segm("a/")
        .path_segm("b")
        .query("spaced key", "123")
        .query("key", "<>")

Query and path segments could also be slices.

Uri::builder()
        .base("https://www.example.com:8080")?
        .path(&["a", "b", "c d"])
        .query_pairs(&[("spaced key", "123"),("another","key")])

(edit by Sean)

To track the progress, here's what's done and needs to be done:

  • Introduce http::uri::Builder
  • Builder::scheme()
  • Builder::authority()
  • Builder::host()
  • Builder::port()
  • Builder::path_and_query()
  • `Builder::path()
  • Builder::query()

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-uriArea: Uri and partsB-rfcBlocked: request for comments. More discussion would help move this along.S-featureSeverity: feature. This adds something new.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions