Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Very lightweight HTTP server using Lwt or Async

This branch is 9 commits behind mirage:master

Failed to load latest commit information.
async Do not override user-supplied headers in `post_form` or `redirect`
bin Cohttp-lwt-proxy now successfully works for normal web browsing
examples/async trailing whitespace cleanup
js Fix type in post_form
lib `Request.has_body` does not permit a body to be set for methods that
lib_test add basic request tests
lwt `Server.respond` no longer overrides user-supplied headers that
scripts Fix #142: update the Code generator script
.gitignore Record generated files
.merlin update .merlin for js_of_ocaml
.ocp-indent ocp-indent config file for lwt
.travis-ci.sh Travis: simplify and just test on OPAM 1.2 now
.travis.yml remote -y from opam install as its set by OPAMYES already in env
CHANGES `Server.respond` no longer overrides user-supplied headers that
LICENSE Replace LICENSE with the ISC, which has been true of the individual
Makefile add a `make revdep` convenience target to test reverse dependencies
README.md improve installation instructions
TODO.md remove Async SSL todo
_oasis Merge branch 'request_auth_test' of git://github.com/rgrinberg/ocaml-…
_opam Add several fields and versions constraints in _oasis
_tags
cohttp.install Add cohttp-proxy-lwt to the .install file
myocamlbuild.ml regen oasis
opam cohttp depends on uri>=1.8.0 due to proxy url parsing fix
setup.ml Merge branch 'request_auth_test' of git://github.com/rgrinberg/ocaml-…

README.md

CoHTTP is an OCaml library for creating HTTP daemons. It has a portable HTTP parser, and implementations using various asynchronous programming libraries:

  • Cohttp_lwt_unix uses the Lwt library, and specifically the UNIX bindings.
  • Cohttp_async uses the Async library.
  • Cohttp_lwt exposes an OS-independent Lwt interface, which is used by the the Mirage interface to generate standalone microkernels (see the mirage-http repository).
  • Cohttp_lwt_xhr compiles to a JavaScript module that maps the Cohttp calls to XMLHTTPRequests. This is used to compile OCaml libraries like the GitHub bindings to JavaScript and still run efficiently.

You can implement other targets using the parser very easily. Look at the lib/IO.mli signature and implement that in the desired backend.

You can activate some runtime debugging by setting COHTTP_DEBUG to any value, and all requests and responses will be written to stderr. Further debugging of the connection layer can be obtained by setting CONDUIT_DEBUG to any value.

Installation

Latest stable version should be obtained from opam. Make sure to install the specific backends you want as well. E.g.

$ opam install cohttp lwt js_of_ocaml

You can also obtain the development release:

$ opam pin add cohttp --dev-repo

Simple HTTP server

If you install the Async dependency, then a cohttp-server-async binary will also be built and installed that acts in a similar fashion to the Python SimpleHTTPServer. Just run cohttp-server-async in a directory and it will open up a local port and serve the files over HTTP.

There is also an Lwt version of the SimpleHTTPServer installed as the cohttp-server-lwt binary. The source code for both is in the bin/ subdirectory and is a good starting point for how to write servers using the library.

Something went wrong with that request. Please try again.