diff --git a/cohttp-async/src/client.ml b/cohttp-async/src/client.ml index eaafebb1f7..e3c079619e 100644 --- a/cohttp-async/src/client.ml +++ b/cohttp-async/src/client.ml @@ -15,7 +15,7 @@ end module Net = struct let lookup uri = - let host = Option.value (Uri.host uri) ~default:"localhost" in + let host = Uri.host_with_default ~default:"localhost" uri in match Uri_services.tcp_port_of_uri ~default:"http" uri with | None -> Deferred.Or_error.error_string "Net.lookup: failed to get TCP port form Uri" @@ -29,19 +29,22 @@ module Net = struct | _ -> Or_error.error "Failed to resolve Uri" uri Uri_sexp.sexp_of_t let connect_uri ?interrupt ?ssl_config uri = - lookup uri - |> Deferred.Or_error.ok_exn - >>= fun (host, addr, port) -> - let mode = - match (Uri.scheme uri, ssl_config) with - | Some "https", Some config -> - `OpenSSL (addr, port, config) - | Some "https", None -> - let config = Conduit_async.V2.Ssl.Config.create ~hostname:host () in - `OpenSSL (addr, port, config) - | Some "httpunix", _ -> `Unix_domain_socket host - | _ -> `TCP (addr, port) - in + (match Uri.scheme uri with + | Some "httpunix" -> + let host = Uri.host_with_default ~default:"localhost" uri in + return @@ `Unix_domain_socket host + | _ -> + lookup uri + |> Deferred.Or_error.ok_exn + >>= fun (host, addr, port) -> + return @@ match (Uri.scheme uri, ssl_config) with + | Some "https", Some config -> + `OpenSSL (addr, port, config) + | Some "https", None -> + let config = Conduit_async.V2.Ssl.Config.create ~hostname:host () in + `OpenSSL (addr, port, config) + | _ -> `TCP (addr, port)) + >>= fun mode -> Conduit_async.V2.connect ?interrupt mode end diff --git a/cohttp/src/request.ml b/cohttp/src/request.ml index 8e97cf4b47..61369ddec2 100644 --- a/cohttp/src/request.ml +++ b/cohttp/src/request.ml @@ -38,10 +38,13 @@ let make ?(meth=`GET) ?(version=`HTTP_1_1) ?encoding ?headers uri = | Some h -> h in let headers = Header.add_unless_exists headers "host" - (Uri.host_with_default ~default:"localhost" uri ^ - match Uri.port uri with - | Some p -> ":" ^ string_of_int p - | None -> "") in + (match Uri.scheme uri with + | Some "httpunix" -> "" + | _ -> + Uri.host_with_default ~default:"localhost" uri ^ + match Uri.port uri with + | Some p -> ":" ^ string_of_int p + | None -> "") in let headers = Header.add_unless_exists headers "user-agent" Header.user_agent in let headers =