Skip to content

Commit

Permalink
httpev: add http_bind function
Browse files Browse the repository at this point in the history
setup http_server with http_config binded to systemd socket (by default)
or to provided addr (host:port)
  • Loading branch information
level-a committed Oct 2, 2020
1 parent 6c1b06d commit be187d3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions httpev.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,21 @@ let setup_lwt config answer =
let server_lwt config answer =
Lwt_main.run @@ setup_lwt config answer

let http_bind addr http_config =
match addr, Systemd.Daemon.listen_fds_lwt () with
| None, [] ->
log#error "bind not provided and no systemd socket available";
exit 1
| None, fd :: fds ->
log#info "starting httpev in systemd mode";
if fds <> [] then
log#warn "more than one fd is provided by systemd, only the first one is used and the other ones are ignored";
setup_fd_lwt fd http_config, "systemd socket"
| Some bind, _ ->
let connection = Nix.sockaddr_of_string bind in
let signature = sprintf "listen %s" (Nix.show_addr connection) in
setup_lwt { http_config with connection }, signature

module Answer = struct

let return ?(status=`Ok) ?(extra=[]) ~typ data : [> `Body of reply_status reply' ] Lwt.t =
Expand Down

0 comments on commit be187d3

Please sign in to comment.