Skip to content

Commit

Permalink
[http] Http.Url.to_string
Browse files Browse the repository at this point in the history
Signed-off-by: David Scott <dave.scott@eu.citrix.com>
  • Loading branch information
David Scott committed Apr 22, 2012
1 parent 66cf999 commit 55ce809
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions http-svr/http.ml
Expand Up @@ -588,6 +588,17 @@ module Url = struct
| x :: _ -> failwith (Printf.sprintf "Unknown scheme %s" x)
| _ -> failwith (Printf.sprintf "Failed to parse URL: %s" url)

let to_string = function
| File ({ path = path }, uri) -> Printf.sprintf "file:%s/%s" path uri (* XXX *)
| Http (h, uri) ->
let userpassat = match h.auth with
| Some (Basic (username, password)) -> Printf.sprintf "%s:%s@" username password
| _ -> "" in
let colonport = match h.port with
| Some x -> Printf.sprintf ":%d" x
| _ -> "" in
Printf.sprintf "http://%s%s%s%s" userpassat h.host colonport uri

let uri_of = function
| File (_, x) -> x
| Http (_, x) -> x
Expand Down
2 changes: 2 additions & 0 deletions http-svr/http.mli
Expand Up @@ -184,6 +184,8 @@ module Url : sig

val of_string: string -> t

val to_string: t -> string

val uri_of: t -> string

val auth_of: t -> authorization option
Expand Down

0 comments on commit 55ce809

Please sign in to comment.