Skip to content

Commit be187d3

Browse files
committed
httpev: add http_bind function
setup http_server with http_config binded to systemd socket (by default) or to provided addr (host:port)
1 parent 6c1b06d commit be187d3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

httpev.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,21 @@ let setup_lwt config answer =
11191119
let server_lwt config answer =
11201120
Lwt_main.run @@ setup_lwt config answer
11211121

1122+
let http_bind addr http_config =
1123+
match addr, Systemd.Daemon.listen_fds_lwt () with
1124+
| None, [] ->
1125+
log#error "bind not provided and no systemd socket available";
1126+
exit 1
1127+
| None, fd :: fds ->
1128+
log#info "starting httpev in systemd mode";
1129+
if fds <> [] then
1130+
log#warn "more than one fd is provided by systemd, only the first one is used and the other ones are ignored";
1131+
setup_fd_lwt fd http_config, "systemd socket"
1132+
| Some bind, _ ->
1133+
let connection = Nix.sockaddr_of_string bind in
1134+
let signature = sprintf "listen %s" (Nix.show_addr connection) in
1135+
setup_lwt { http_config with connection }, signature
1136+
11221137
module Answer = struct
11231138

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

0 commit comments

Comments
 (0)