[ANN] Shuttle 0.9.1 released

Some new updates since the last release:

  • shuttle_http now supports HTTP/1.1 servers that use async_ssl based 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_websocket that provides the web socket upgrade negotiation for servers, and allows converting a web socket handler to a request -> response promise based http service that can be used by shuttle_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
2 Likes