Some new updates since the last release:
shuttle_httpnow supports HTTP/1.1 servers that useasync_sslbased encrypted connections.- A server context is forwarded to http services. This context can be used to lookup peer client’s address, check if the http service is running on a SSL encrypted server, and if SSL is used lookup peer client’s SSL certificates.
- HTTP servers support web socket upgrades now. The implementation is based on Janestreet’s web socket library (GitHub - janestreet/async_websocket: A library that implements the websocket protocol on top of Async), and shuttle has a companion library
shuttle_websocketthat provides the web socket upgrade negotiation for servers, and allows converting a web socket handler to arequest -> response promisebased http service that can be used byshuttle_http.
Example for a http service that serves web socket traffic on some requests:
open! Core
open! Async
open Shuttle_http
let websocket_handler =
Shuttle_websocket.create (fun ws ->
let rd, wr = Websocket.pipes ws in
Pipe.transfer_id rd wr)
;;
let service context request =
Log.Global.info "Peer address: %s" (Socket.Address.to_string (Server.peer_addr context));
match Request.path request with
| "/websocket"-> websocket_handler request
| "/" -> return (Response.create ~body:(Body.string "Hello World") `Ok)
| _ -> return (Response.create `Not_found)
;;
The latest release has been published to the opam package repository, and can be installed via opam:
opam install shuttle_http
opam install shuttle_websocket