Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse URI without authority component #469

Open
maxlambrecht opened this issue Mar 3, 2021 · 6 comments
Open

Cannot parse URI without authority component #469

maxlambrecht opened this issue Mar 3, 2021 · 6 comments

Comments

@maxlambrecht
Copy link

maxlambrecht commented Mar 3, 2021

Trying to parse an URI like unix:///tmp/agent.sock or unix:/tmp/agent.sock, that has a schema and not an authority, produces an Error InvalidaUri(InvalidFormat).

There is no restriction defined in the URI standard that would make these URIs invalid.

The use-case I have is connecting to a SPIFFE Workload Endpoint: https://github.com/spiffe/spiffe/blob/master/standards/SPIFFE_Workload_Endpoint.md#4-locating-the-endpoint.

@adamreichold
Copy link

I think I am hitting a similar issue where a location header that contains a path is parsed as an authority

[tests/path.rs:5] "forum".parse::<Uri>().unwrap().into_parts() = Parts {
    scheme: None,
    authority: Some(
        forum,
    ),
    path_and_query: None,
    _priv: (),
}

or not at all if it has a trailing slash

[tests/path.rs:5] "forum/".parse::<Uri>() = Err(
    InvalidUri(
        InvalidFormat,
    ),
)

@nox
Copy link
Contributor

nox commented Sep 19, 2021

@adamreichold What you pasted is orthogonal to the ticket and AFAIK both your pastes aren't bugs.

@adamreichold
Copy link

@nox Thank you for looking into this! Can you go into slightly more detail why both instances are valid behaviour so that I can better understand how to work around this? Thanks!

@nox
Copy link
Contributor

nox commented Sep 19, 2021

The Uri type in that crate was mostly designed to represent a HTTP request target as defined in https://httpwg.org/specs/rfc7230.html#request-target.

  • origin-form is more or less an absolute path, that starts with /.
  • absolute-form is a complete URL in all its glory, with the scheme etc.
  • authority-form is well, an authority, that is, the localhost part in http://localhost/, that's your first example.
  • asterisk-form is just *, used for OPTIONS requests for example.

So this covers the first example forum, which as you've stated is successfully.

If you read the rules for those 4 cases, you'll notice that the only forms that can accept a / are origin-form and absolute-form, and that forum/ fits neither, hence the error you've encountered.

@adamreichold
Copy link

The Uri type in that crate was mostly designed to represent a HTTP request target

So basically, this boils down to Uri handling request-target but not URI-reference in the parlance of RFC 7230. 🤔

@nox
Copy link
Contributor

nox commented Sep 20, 2021

Yes, cause it represents an URI in the context of a HTTP request/response cycle, where GET forum HTTP/1.0 is not valid.

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

No branches or pull requests

3 participants