├── .gitignore ├── .ocamlformat ├── .ocp-indent ├── .travis.yml ├── CHANGES ├── LICENSE.md ├── META.websocket.template ├── Makefile ├── README.md ├── RELEASE.md ├── core ├── dune ├── sha1.ml ├── websocket.ml └── websocket.mli ├── dune-project ├── lwt ├── dune ├── websocket_cohttp_lwt.ml ├── websocket_cohttp_lwt.mli ├── websocket_lwt_unix.ml ├── websocket_lwt_unix.mli └── wscat.ml ├── test ├── dune ├── reynir.ml └── upgrade_connection.ml ├── websocket-lwt-unix.opam └── websocket.opam /.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | **/*.merlin 3 | *.install 4 | _opam -------------------------------------------------------------------------------- /.ocamlformat: -------------------------------------------------------------------------------- 1 | profile = default 2 | break-separators = after 3 | -------------------------------------------------------------------------------- /.ocp-indent: -------------------------------------------------------------------------------- 1 | strict_with=always,match_clause=2,strict_else=never 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: required 3 | install: test -e .travis.opam.sh || wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh 4 | script: 5 | - bash -ex .travis-opam.sh 6 | env: 7 | matrix: 8 | - OCAML_VERSION="4.09" PACKAGE="websocket" 9 | - OCAML_VERSION="4.09" PACKAGE="websocket-lwt-unix" 10 | - OCAML_VERSION="4.09" PACKAGE="websocket-async" 11 | os: 12 | - linux 13 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 2.17 (2024-09-07) Nancy 2 | ----------------------- 3 | 4 | - adapt to mirage-crypto (@copy) 5 | - use mirage-crypto-rng as csprng (@ushitora-anqou) 6 | 7 | 2.16 (2023-01-02) Nancy 8 | ----------------------- 9 | 10 | - flush output after writing frames 11 | - ocamlformat: use default profile 12 | - async: Adapt to Core/Async v0.15 13 | 14 | 2.15 (2021-03-16) Nancy 15 | ----------------------- 16 | 17 | - Lwt (interface): abstract conn type (@paurkedal) 18 | - Lwt (name change): with_connection -> connect 19 | - Cohttp: adapt to new version (@kit-ty-kate) 20 | - Conduit: adapt to new version (@MisterDA) 21 | 22 | 2.14 (2020-03-5) Paris 23 | ---------------------- 24 | 25 | - bugfix: cohttp_lwt: call conn_closed on fd close (@NightBlues) 26 | - fix compilation with newer async (@copy) 27 | - fix compilation with newer conduit (@tizoc) 28 | 29 | 2.13 (2019-03-17) 30 | ----------------- 31 | 32 | - Async: use logs_async 33 | - Async: upgrade_connection API (@kkazuo) 34 | - Lwt: fix upgrade_connection for TLS (API change) 35 | - Upgrade Base64 support to 3.1.0 36 | 37 | 2.12 (2018-10-01) 38 | ----------------- 39 | 40 | - build: switch to `dune` 41 | 42 | 2.11 (2017-12-19) 43 | ----------------- 44 | 45 | - Lwt: fix compilation for Cohttp_lwt_unix >= 1.0 46 | 47 | 2.10 (2017-08-01) 48 | ----------------- 49 | 50 | - Build: use jbuilder 51 | - Lwt: add `check_origin` (@zoggy) 52 | - Lwt: add `send_multiple` (@copy) 53 | 54 | 2.9 (2017-03-20) 55 | ----------------- 56 | 57 | - Lwt: rename ?exception_handler to ?on_exn, to match Conduit 58 | - Async: Add ?check_request with the same interface as Lwt backend 59 | - Fix compilation with the dev version of Async 60 | 61 | 2.8 (2017-03-01) 62 | ---------------- 63 | 64 | - drop dependency to ppx_deriving 65 | - bugfix: fix corrupted received frame (@zoggy) 66 | 67 | 2.7 (2017-02-21) 68 | ---------------- 69 | 70 | - new websocket.cohttp package to upgrade to websocket from cohttp (@SimonJF) 71 | - lwt: function `source' now covers all conduit cases 72 | - async: refactoring and fixes 73 | - perf improvement (Avoid generating xor mask if it isn't used) (@copy) 74 | - remove dependency to containers library 75 | - lwt: Add callback to check origin before websocket connection (@copy) 76 | - lwt: Improve error handling in lwt server (@copy) 77 | - async: more efficient logging 78 | 79 | 2.6 (2016-09-17) 80 | ---------------- 81 | 82 | - async: client_ez: kill the connection on absence of PONG reply 83 | - async: client_ez: fix PONG watch code 84 | - websocket: use read_exactly (@copy) 85 | 86 | 2.5 (2016-08-16) 87 | ---------------- 88 | 89 | - async: client_ez: add an ?opcode argument 90 | - lwt: unset async_exception_hook (@copy) 91 | 92 | 2.4 (2016-07-26) 93 | ---------------- 94 | 95 | - bugfix: Handle truncated cohttp stream reads (@kayceesrk) 96 | - cleanup: Async version does not depend on containers anymore 97 | - build: fix META generation, fixing Async-only installation 98 | 99 | 2.3 (2016-06-29) 100 | ---------------- 101 | 102 | - async: bugfix: fix fd leak that occurred when pipes were not closed 103 | - async: log, name as optional args in functions 104 | - lwt server: support from connection upgrade (@lostman) 105 | - bugfix: fix reading int64 encoded frame size 106 | - async server: bugfixes and interface improvement (@copy) 107 | - parametrize random string generation (@j0sh) 108 | - async client: minor improvements 109 | 110 | 2.2 (2015-12-23) 111 | ---------------- 112 | 113 | - Async backend 114 | - Code refactoring, bugfixes and upgrade to new version of libraries 115 | 116 | 2.1 (2015-07-07) 117 | ---------------- 118 | 119 | - server: Pass in a Cohttp.Request.t instead of Uri.t 120 | - add Websocket_Lwt.{mk_frame_stream,establish_standard_server} 121 | - websocket_lwt.cm{a,xa} now only contains module Websocket_lwt 122 | - Fix upgrade, keepalive issue with Firefox regression 123 | - Websocket_lwt: Use entropy generator 124 | 125 | 2.0.0 (2015-06-18) 126 | ------------------ 127 | 128 | - Breaking API change: not Lwt_stream based anymore 129 | - Switch to conduit (TLS) 130 | - Functorisation of common code, new Websocket_lwt module 131 | - More RFC compliance using Autobahn Test Suite 132 | - Bugfixes 133 | 134 | 0.9.3 (2015-03-23) 135 | ------------------ 136 | 137 | - Support TLS 0.4.0+ API. 138 | 139 | 0.9.2 (2015-02-10) 140 | ------------------ 141 | 142 | - Bugfix: Do not verify result of setsockopt 143 | 144 | 0.9.1 (2015-01-03) 145 | ------------------ 146 | 147 | - safe_string 148 | - fix a critical bug that when handling masked frames 149 | 150 | 0.9 (2014-08-21) 151 | ---------------- 152 | 153 | - Drop support for OCaml < 4 154 | - Replace Cryptokit by Nocrypto 155 | - Replace Lwt_ssl by Tls_lwt for TLS 156 | - Add TLS support for the websocket server 157 | - Replace OASIS by topkg 158 | - Removing camlp4 159 | - Minor interface changes 160 | 161 | 0.8.2 (2014-06-09) 162 | ------------------ 163 | 164 | - [doc] Add a warning in the doc of `establish_server` 165 | - Close frame now contain a status code (TODO: expose it somewhere) 166 | - Fix fd leakages (hopefully the library should not leak any fds anymore) 167 | - Use OASIS' compiled_setup_ml feature 168 | 169 | 0.8.1 (2014-03-26) 170 | ------------------ 171 | 172 | - Upgrade to OASIS 0.4 173 | 174 | 0.8 (2014-03-26) 175 | ---------------- 176 | 177 | - decode connection upgrade header with regex 178 | 179 | 0.7 (2014-03-02) 180 | ---------------- 181 | 182 | - New "extra_headers" optional argument for {open,with}_connection (acm) 183 | - Port to cohttp 0.10.x API (avsm) 184 | 185 | 0.6 (2013-08-20) 186 | ---------------- 187 | 188 | - Added SSL support for the client. 189 | 190 | 0.5 (2013-05-06) 191 | ---------------- 192 | 193 | - First working release. 194 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Vincent Bernardoff 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /META.websocket.template: -------------------------------------------------------------------------------- 1 | # JBUILDER_GEN 2 | 3 | package "lwt" ( 4 | description = "Deprecated. Use websocket-lwt directly" 5 | requires = "websocket-lwt" 6 | ) 7 | 8 | package "async" ( 9 | description = "Deprecated. Use websocket-async directly" 10 | requires = "websocket-async" 11 | ) 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | dune build @all 3 | 4 | clean: 5 | dune clean 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ocaml-websocket — Websocket library for OCaml 2 | --------------------------------------------- 3 | 4 | The WebSocket Protocol enables two-way communication between a client 5 | running untrusted code in a controlled environment to a remote host 6 | that has opted-in to communications from that code. 7 | 8 | The security model used for this is the origin-based security model 9 | commonly used by web browsers. The protocol consists of an opening 10 | handshake followed by basic message framing, layered over TCP. 11 | 12 | The goal of this technology is to provide a mechanism for 13 | browser-based applications that need two-way communication with 14 | servers that does not rely on opening multiple HTTP connections (e.g., 15 | using XMLHttpRequest or