Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpev: add http_bind function #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions httpev.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ let default =

include Httpev_common

type http_server_bind =
| Systemd of Lwt_unix.file_descr
| Connection of Unix.sockaddr

type partial_body = {
line1 : string;
content_length : int option;
Expand Down Expand Up @@ -1119,6 +1123,24 @@ let setup_lwt config answer =
let server_lwt config answer =
Lwt_main.run @@ setup_lwt config answer

let setup_bind_lwt addr config answer =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is config.connection which this api totally ignores which is not cool. Instead we should break api and make config.connection a variant itself and make all setup_* functions honor that variant and provide convenience functions to set that variant

let connection =
match addr, Systemd.Daemon.listen_fds_lwt () with
| None, [] -> Exn.fail "bind not provided and no systemd socket available"
| None, fd :: fds ->
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";
Systemd fd
| Some addr, _ -> Connection addr
in
match connection with
| Systemd fd ->
log#info "starting httpev in systemd mode";
setup_fd_lwt fd config answer
| Connection connection ->
log#info "starting httpev on %s" (Nix.show_addr connection);
setup_lwt { config with connection } answer

module Answer = struct

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