-
Notifications
You must be signed in to change notification settings - Fork 284
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
CP-49647 use URI to build URIs #5650
CP-49647 use URI to build URIs #5650
Conversation
@@ -399,10 +399,14 @@ let pool_migrate ~__context ~vm ~host ~options = | |||
use_compression ~__context options (Helpers.get_localhost ~__context) host | |||
in | |||
debug "%s using stream compression=%b" __FUNCTION__ compress ; | |||
let ip = Http.Url.maybe_wrap_IPv6_literal address in | |||
let scheme = if !Xapi_globs.migration_https_only then "https" else "http" in | |||
let http = if !Xapi_globs.migration_https_only then "https" else "http" in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be scheme
, because it can be either 'http' or 'https'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But scheme
inside URI
is bound and shadows it when using it in URI.(make ... scheme)
. So I would have to give up opening URI
to use scheme
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that make it simpler?
Uri.(
make ~scheme ~host:...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with Uri.(..)
is that scheme
and so on are functions inside Uri
that shadow my bindings. So now I prefer to not open Uri
and avoid this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see... In the following commit you have Uri.make ... |> Uri.to_string
to avoid this.
| Http h, data -> | ||
let userpassat = | ||
(* this should have file:// *) | ||
Printf.sprintf "file:%s%s" path (data_to_string data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe Uri can be used here as well, and in all cases, hopefully.
I'd try to generate the parameters for Uri.make
:
let scheme, host, port, userinfo, path, query = match url with
| File {path}, data ->
"file", None, None, None, (Printf.sprintf "%s%s" path (data_to_string data)), None
...
in
Uri.(make ~scheme ~host ~port ~userinfo ~path ~query |> to_string)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code above does not work because scheme
, host
and so on become shadowed once Uri
is open:
utop # let host = "localhost" in Uri.(make ~host () |> to_string);;
Error: This expression has type t -> string option
but an expression was expected of type string
But could use Uri.make
and Uri.to_string
explicitly.
132d580
to
3439839
Compare
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
3439839
to
c1e84a2
Compare
This has gone through BVT/BST |
ocaml/xe-cli/newcli.ml
Outdated
let ( let* ) = Option.bind in | ||
let* scheme = Uri.scheme uri in | ||
let* host = Uri.host uri in | ||
let path = Uri.path uri in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this now include the query string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops - this commit should not be included; will take a look
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
76afca7
to
2b59034
Compare
Printf.sprintf "%s://%s/" scheme | ||
(Http.Url.maybe_wrap_IPv6_literal master_address) | ||
in | ||
let master_url = Uri.make ~scheme ~host:master_address () |> Uri.to_string in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to omit the trailing /
. That is probably not an issue, but we should check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on testing it's not an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, assuming all the aforementioned implicit shadowing captures are mitigated.
Shadowing is caught by the type checker because it's simple values versus functions. |
For improved IPv6 compatibility, use URI to build URIs. In particular, this will take care of bracketing IPv6 addresses in URIs.