mirage / ocaml-uri

RFC3986 URI parsing library for OCaml
Other
97 stars 57 forks source link

Behavior of with_path #85

Closed fxfactorial closed 8 years ago

fxfactorial commented 9 years ago

Say I have a URI of

https://api.stripe.com/v1/charges as Uri.t

and then I want to add something like "q2asddf_token_thing" so that the final Uri.t will be:

https://api.stripe.com/v1/charges/q2asddf_token_thing

I don't want to do string level conversions/concating of course, so I thought Uri.with_path would help me here but all it does is completely replace the path giving me this instead:

https://api.stripe.com/q2asddf_token_thing

Is this correct behavior? To me this is bad.

dsheets commented 8 years ago

This is the correct behavior. You can achieve what you want without string manipulation using something like:

Uri.(resolve ""
       (of_string "https://api.stripe.com/v1/charges")
       (of_string "charges/q2asddf_token_thing"));;

This, of course, should be easier but the library currently does not provide any path segment manipulation. The charges/ prefix is required because charges at the end of the base is not a directory-like segment and so the relative path from it to a child must re-iterate its name.

Sorry for the response delay; I have been traveling for several weeks. I'll leave this issue open if you'd like to discuss this further.

fxfactorial commented 8 years ago

@dsheets Thanks. This is ugly but okay.