-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cohttp-lwt-unix-nossl and cohttp-lwt-unix-ssl (update cohttp-lwt-…
…unix to use cohttp-lwt-unix-nossl)
- Loading branch information
Showing
26 changed files
with
447 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
opam-version: "2.0" | ||
maintainer: "[email protected]" | ||
authors: [ | ||
"Anil Madhavapeddy" | ||
"Stefano Zacchiroli" | ||
"David Sheets" | ||
"Thomas Gazagnaire" | ||
"David Scott" | ||
"Rudi Grinberg" | ||
"Andy Ray" | ||
] | ||
synopsis: "CoHTTP implementation for Unix and Windows using Lwt" | ||
description: """ | ||
An implementation of an HTTP client and server using the Lwt | ||
concurrency library. See the `Cohttp_lwt_unix` module for information | ||
on how to use this. The package also installs `cohttp-curl-lwt` | ||
and a `cohttp-server-lwt` binaries for quick uses of a HTTP(S) | ||
client and server respectively. | ||
|
||
Although the name implies that this only works under Unix, it | ||
should also be fine under Windows too.""" | ||
license: "ISC" | ||
tags: ["org:mirage" "org:xapi-project"] | ||
homepage: "https://github.com/mirage/ocaml-cohttp" | ||
doc: "https://mirage.github.io/ocaml-cohttp/" | ||
bug-reports: "https://github.com/mirage/ocaml-cohttp/issues" | ||
depends: [ | ||
"ocaml" {>= "4.04.1"} | ||
"dune" {>= "1.1.0"} | ||
"conduit-lwt" {>= "1.0.3"} | ||
"ca-certs" | ||
"cmdliner" | ||
"magic-mime" | ||
"logs" | ||
"fmt" {>= "0.8.2"} | ||
"cohttp-lwt" {=version} | ||
"lwt" {>= "3.0.0"} | ||
"base-unix" | ||
"ounit" {with-test} | ||
] | ||
build: [ | ||
["dune" "subst"] {pinned} | ||
["dune" "build" "-p" name "-j" jobs] | ||
["dune" "runtest" "-p" name "-j" jobs] {with-test} | ||
] | ||
dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git" | ||
pin-depends: [ | ||
[ "conduit.dev" "git+https://github.com/mirage/ocaml-conduit.git#4b9e8b0f8e96459c8e27ca27ed7416b8d1b5ba23" ] | ||
[ "conduit-lwt.dev" "git+https://github.com/mirage/ocaml-conduit.git#4b9e8b0f8e96459c8e27ca27ed7416b8d1b5ba23" ] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
include Cohttp_lwt.Make_client(Io)(Net) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
(** The [Client] module implements the full UNIX HTTP client interface, | ||
including the UNIX-specific functions defined in {!C }. *) | ||
|
||
include Cohttp_lwt.S.Client with type ctx = Conduit.resolvers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(*{{{ Copyright (c) 2012 Anil Madhavapeddy <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
}}}*) | ||
|
||
module Request = struct | ||
include Cohttp.Request | ||
include (Make(Io) | ||
: module type of Make(Io) with type t := t) | ||
end | ||
|
||
module Response = struct | ||
include Cohttp.Response | ||
include (Make(Io) | ||
: module type of Make(Io) with type t := t) | ||
end | ||
|
||
module Client = Client | ||
module Server = Server | ||
module Debug = Debug | ||
module Net = Net | ||
module IO = Io |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(library | ||
(name cohttp_lwt_unix_nossl) | ||
(public_name cohttp-lwt-unix-nossl) | ||
(synopsis "Lwt/Unix backend for Cohttp") | ||
(preprocess | ||
(pps ppx_sexp_conv)) | ||
(libraries fmt logs logs.lwt conduit-lwt magic-mime lwt.unix | ||
cohttp cohttp-lwt)) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(*{{{ Copyright (c) 2012 Anil Madhavapeddy <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
}}}*) | ||
|
||
(* Miscellaneous net-helpers used by Cohttp. Ideally, these will disappear | ||
* into some connection-management framework such as andrenth/release *) | ||
|
||
open Lwt.Infix | ||
|
||
module IO = Io | ||
|
||
type ctx = (Conduit.resolvers[@sexp.opaque]) [@@deriving sexp] | ||
|
||
let default_ctx = Conduit_lwt.empty | ||
|
||
let failwith fmt = Format.kasprintf (fun err -> Lwt.fail (Failure err)) fmt | ||
|
||
let uri_to_endpoint uri = | ||
(match Uri.host uri with | ||
| None -> failwith "Invalid uri: no host component in %a" Uri.pp uri | ||
| Some h -> Lwt.return h) >>= fun v -> | ||
let ( >>= ) x f = match x with Ok x -> f x | Error err -> Error err in | ||
match Domain_name.(of_string v >>= host), Ipaddr.of_string v with | ||
| Ok domain_name, _ -> Lwt.return (Conduit.Endpoint.domain domain_name) | ||
| Error _, Ok v -> Lwt.return (Conduit.Endpoint.ip v) | ||
| Error _, Error _ -> failwith "Invalid uri: %a" Uri.pp uri | ||
|
||
let connect_uri ~ctx uri = | ||
uri_to_endpoint uri >>= fun edn -> | ||
let ctx = match Uri.scheme uri with | ||
| (Some "http" | None) -> | ||
let port = Option.value ~default:80 (Uri.port uri) in | ||
Conduit_lwt.add Conduit_lwt.TCP.protocol (Conduit_lwt.TCP.resolve ~port) ctx | ||
| _ -> ctx in | ||
Conduit_lwt.resolve ctx edn >>= function | ||
| Ok flow -> | ||
let ic, oc = Conduit_lwt.io_of_flow flow in | ||
Lwt.return (flow, ic, oc) | ||
| Error err -> | ||
failwith "%a" Conduit_lwt.pp_error err | ||
|
||
let close c = Lwt.catch | ||
(fun () -> Lwt_io.close c) | ||
(fun e -> | ||
Logs.warn (fun f -> f "Closing channel failed: %s" (Printexc.to_string e)); | ||
Lwt.return_unit | ||
) | ||
|
||
let close_in ic = Lwt.ignore_result (close ic) | ||
|
||
let close_out oc = Lwt.ignore_result (close oc) | ||
|
||
let close ic oc = Lwt.ignore_result (close ic >>= fun () -> close oc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(*{{{ Copyright (c) 2015 David Sheets <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
}}}*) | ||
|
||
(** Basic satisfaction of {! Cohttp_lwt.Net } *) | ||
|
||
module IO = Io | ||
|
||
type ctx = (Conduit.resolvers[@sexp.opaque]) [@@deriving sexp] | ||
|
||
val default_ctx : ctx | ||
|
||
(** Exceptions from [conduit]. | ||
When the [recv] or the [send] {i syscalls} return an error, | ||
[conduit] will reraise it. *) | ||
|
||
val connect_uri : | ||
ctx:ctx -> | ||
Uri.t -> | ||
(Conduit_lwt.flow * Lwt_io.input Lwt_io.channel * Lwt_io.output Lwt_io.channel) Lwt.t | ||
|
||
val close_in : 'a Lwt_io.channel -> unit | ||
val close_out : 'a Lwt_io.channel -> unit | ||
|
||
val close : 'a Lwt_io.channel -> 'b Lwt_io.channel -> unit |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
opam-version: "2.0" | ||
maintainer: "[email protected]" | ||
authors: [ | ||
"Anil Madhavapeddy" | ||
"Stefano Zacchiroli" | ||
"David Sheets" | ||
"Thomas Gazagnaire" | ||
"David Scott" | ||
"Rudi Grinberg" | ||
"Andy Ray" | ||
] | ||
synopsis: "CoHTTP implementation for Unix and Windows using Lwt" | ||
description: """ | ||
An implementation of an HTTP client and server using the Lwt | ||
concurrency library. See the `Cohttp_lwt_unix` module for information | ||
on how to use this. The package also installs `cohttp-curl-lwt` | ||
and a `cohttp-server-lwt` binaries for quick uses of a HTTP(S) | ||
client and server respectively. | ||
|
||
Although the name implies that this only works under Unix, it | ||
should also be fine under Windows too.""" | ||
license: "ISC" | ||
tags: ["org:mirage" "org:xapi-project"] | ||
homepage: "https://github.com/mirage/ocaml-cohttp" | ||
doc: "https://mirage.github.io/ocaml-cohttp/" | ||
bug-reports: "https://github.com/mirage/ocaml-cohttp/issues" | ||
depends: [ | ||
"ocaml" {>= "4.04.1"} | ||
"dune" {>= "1.1.0"} | ||
"conduit-lwt" {>= "1.0.3"} | ||
"conduit-lwt-ssl" | ||
"ca-certs" | ||
"cmdliner" | ||
"magic-mime" | ||
"logs" | ||
"fmt" {>= "0.8.2"} | ||
"cohttp-lwt" {=version} | ||
"cohttp-lwt-unix-nossl" {=version} | ||
"lwt" {>= "3.0.0"} | ||
"base-unix" | ||
"ounit" {with-test} | ||
] | ||
build: [ | ||
["dune" "subst"] {pinned} | ||
["dune" "build" "-p" name "-j" jobs] | ||
["dune" "runtest" "-p" name "-j" jobs] {with-test} | ||
] | ||
dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git" | ||
pin-depends: [ | ||
[ "conduit.dev" "git+https://github.com/mirage/ocaml-conduit.git#4b9e8b0f8e96459c8e27ca27ed7416b8d1b5ba23" ] | ||
[ "conduit-tls.dev" "git+https://github.com/mirage/ocaml-conduit.git#4b9e8b0f8e96459c8e27ca27ed7416b8d1b5ba23" ] | ||
[ "conduit-lwt-ssl.dev" "git+https://github.com/mirage/ocaml-conduit.git#4b9e8b0f8e96459c8e27ca27ed7416b8d1b5ba23" ] | ||
[ "conduit-lwt.dev" "git+https://github.com/mirage/ocaml-conduit.git#4b9e8b0f8e96459c8e27ca27ed7416b8d1b5ba23" ] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
include Cohttp_lwt.Make_client(Cohttp_lwt_unix_nossl.IO)(Net) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
(** The [Client] module implements the full UNIX HTTP client interface, | ||
including the UNIX-specific functions defined in {!C }. *) | ||
|
||
include Cohttp_lwt.S.Client with type ctx = Conduit.resolvers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(*{{{ Copyright (c) 2012 Anil Madhavapeddy <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
}}}*) | ||
|
||
module Request = struct | ||
include Cohttp.Request | ||
include (Make(Cohttp_lwt_unix_nossl.IO) | ||
: module type of Make(Cohttp_lwt_unix_nossl.IO) with type t := t) | ||
end | ||
|
||
module Response = struct | ||
include Cohttp.Response | ||
include (Make(Cohttp_lwt_unix_nossl.IO) | ||
: module type of Make(Cohttp_lwt_unix_nossl.IO) with type t := t) | ||
end | ||
|
||
module Client = Client | ||
module Server = Cohttp_lwt_unix_nossl.Server | ||
module Debug = Cohttp_lwt_unix_nossl.Debug | ||
module Net = Net | ||
module IO = Cohttp_lwt_unix_nossl.IO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(library | ||
(name cohttp_lwt_unix_ssl) | ||
(public_name cohttp-lwt-unix-ssl) | ||
(synopsis "Lwt/Unix (with OpenSSL) backend for Cohttp") | ||
(preprocess | ||
(pps ppx_sexp_conv)) | ||
(libraries fmt logs logs.lwt conduit-lwt conduit-lwt-ssl magic-mime lwt.unix | ||
cohttp cohttp-lwt cohttp-lwt-unix-nossl)) |
Oops, something went wrong.