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

Use httpun / httpun-types / httpun-ws #203

Merged
merged 15 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 4 additions & 7 deletions .github/workflows/opam-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}

- name: Install locally
run: |
opam pin add eio --dev-repo -y
opam pin add eio_linux --dev-repo -y
opam pin add eio_posix --dev-repo -y
opam pin add eio_main --dev-repo -y
opam install .
env:
EIO_BACKEND: posix
run: opam pin add piaf.dev . --with-test -y
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"runs-on": "macos-latest",
"steps": [
{
"uses": "actions/checkout@v2",
"uses": "actions/checkout@v4",
"with": {
"submodules": "recursive"
}
},
{
"uses": "cachix/install-nix-action@v22",
"uses": "cachix/install-nix-action@v27",
"with": {
"extra_nix_config": "extra-substituters = https://anmonteiro.nix-cache.workers.dev\nextra-trusted-public-keys = ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY=\n"
}
Expand All @@ -24,8 +24,8 @@
"fail-fast": false,
"matrix": {
"ocamlVersion": [
"5_0",
"5_1"
"5_1",
"5_2"
]
}
}
Expand All @@ -34,13 +34,13 @@
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v2",
"uses": "actions/checkout@v4",
"with": {
"submodules": "recursive"
}
},
{
"uses": "cachix/install-nix-action@v22",
"uses": "cachix/install-nix-action@v27",
"with": {
"extra_nix_config": "extra-substituters = https://anmonteiro.nix-cache.workers.dev\nextra-trusted-public-keys = ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY=\n"
}
Expand All @@ -54,8 +54,8 @@
"fail-fast": false,
"matrix": {
"ocamlVersion": [
"5_0",
"5_1"
"5_1",
"5_2"
]
}
}
Expand Down
7 changes: 0 additions & 7 deletions .gitmodules

This file was deleted.

9 changes: 5 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
(ssl :dev)
uri
ipaddr
(httpaf-eio :dev)
(gluten-eio :dev)
httpun-eio
gluten-eio
(h2-eio :dev)
(websocketaf :dev)
(httpun-ws :dev)
(multipart_form :dev)
(eio_main :dev)
(eio_main
(>= "1.0"))
(dune-site :with-test)
(alcotest :with-test)))
26 changes: 13 additions & 13 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}".extend (self: super: {
ocamlPackages = super.ocaml-ng.ocamlPackages_5_1;
ocamlPackages = super.ocaml-ng.ocamlPackages_5_2;
});
in
rec {
Expand Down
2 changes: 1 addition & 1 deletion lib/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ let ws_upgrade :
* [RFC4648]). The nonce MUST be selected randomly for each connection. *)
let nonce = Openssl.random_string 16 in
Ws.upgrade_request
~headers:(Httpaf.Headers.of_list headers)
~headers:(Httpun.Headers.of_list headers)
~scheme:info.scheme
~nonce
target
Expand Down
2 changes: 1 addition & 1 deletion lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let default =
}

let to_http1_config { body_buffer_size; buffer_size; _ } =
{ Httpaf.Config.read_buffer_size = buffer_size
{ Httpun.Config.read_buffer_size = buffer_size
; response_buffer_size = buffer_size
; request_body_buffer_size = body_buffer_size
; response_body_buffer_size = body_buffer_size
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*---------------------------------------------------------------------------*)

open Import
module Version = Httpaf.Version
module Version = Httpun.Version

module Logs =
(val Logging.setup ~src:"piaf.connection" ~doc:"Piaf Connection module")
Expand Down
6 changes: 3 additions & 3 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
multipart
h2
h2-eio
httpaf
httpaf-eio
websocketaf
httpun
httpun-eio
httpun-ws
logs
eio
eio-ssl
Expand Down
6 changes: 3 additions & 3 deletions lib/headers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Well_known = struct
end

let add_length_related_headers ~version ~body_length headers =
(* TODO: check `Httpaf.Response.body_length` because we may have to issue a
(* TODO: check `Httpun.Response.body_length` because we may have to issue a
* 0-length response body. *)
(* Don't step over an explicit `content-length` header. *)
match body_length with
Expand Down Expand Up @@ -100,5 +100,5 @@ let host t ~version =
| Versions.HTTP.HTTP_2 -> get t Well_known.HTTP2.host
| HTTP_1_0 | HTTP_1_1 -> get t Well_known.HTTP1.host

let of_http1 headers = of_rev_list (Httpaf.Headers.to_rev_list headers)
let to_http1 headers = Httpaf.Headers.of_rev_list (to_rev_list headers)
let of_http1 headers = of_rev_list (Httpun.Headers.to_rev_list headers)
let to_http1 headers = Httpun.Headers.of_rev_list (to_rev_list headers)
44 changes: 22 additions & 22 deletions lib/http1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ module type BODY = Body.Raw.BODY

module Body :
BODY
with type Reader.t = Httpaf.Body.Reader.t
and type Writer.t = Httpaf.Body.Writer.t = struct
module Reader = Httpaf.Body.Reader
module Writer = Httpaf.Body.Writer
with type Reader.t = Httpun.Body.Reader.t
and type Writer.t = Httpun.Body.Writer.t = struct
module Reader = Httpun.Body.Reader
module Writer = Httpun.Body.Writer
end

module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
Http_intf.HTTP1
with type Client.t = Httpaf_eio.Client.t
and type Body.Reader.t = Httpaf.Body.Reader.t
and type Body.Writer.t = Httpaf.Body.Writer.t
with type Client.t = Httpun_eio.Client.t
and type Body.Reader.t = Httpun.Body.Reader.t
and type Body.Writer.t = Httpun.Body.Writer.t
and type scheme = Runtime_scheme.t = struct
type scheme = Runtime_scheme.t

Expand All @@ -55,7 +55,7 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
module Body = Body

module Client = struct
include Httpaf_eio.Client
include Httpun_eio.Client

(* Error handler for HTTP/1 connections isn't used *)
let create_connection ~config ~error_handler:_ ~sw fd =
Expand Down Expand Up @@ -93,9 +93,9 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
let body =
Piaf_body.Raw.to_response_body
(module Body.Reader : Piaf_body.Raw.Reader
with type t = Httpaf.Body.Reader.t)
with type t = Httpun.Body.Reader.t)
~body_length:
(Httpaf.Response.body_length ~request_method response
(Httpun.Response.body_length ~request_method response
:> Piaf_body.length)
body
in
Expand All @@ -104,7 +104,7 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
let error_handler error =
let error : Error.client =
match error with
| `Invalid_response_body_length { Httpaf.Response.status; headers; _ }
| `Invalid_response_body_length { Httpun.Response.status; headers; _ }
->
`Invalid_response_body_length
((status :> H2.Status.t), Headers.of_http1 headers)
Expand All @@ -124,13 +124,13 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
module Server = struct
let request_of_http1 = Request.of_http1 ~scheme:Runtime_scheme.scheme

include Httpaf_eio.Server
include Httpun_eio.Server

module Reqd :
Http_intf.Reqd
with type t = Httpaf.Reqd.t
with type t = Httpun.Reqd.t
and type write_body = Body.Writer.t = struct
include Httpaf.Reqd
include Httpun.Reqd

type write_body = Body.Writer.t

Expand All @@ -156,7 +156,7 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
end

let make_error_handler ~fd error_handler :
Eio.Net.Sockaddr.stream -> Httpaf.Server_connection.error_handler
Eio.Net.Sockaddr.stream -> Httpun.Server_connection.error_handler
=
fun client_addr ?request error start_response ->
let start_response headers = start_response (Headers.to_http1 headers) in
Expand All @@ -169,7 +169,7 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
(Option.value
~default:HTTP_1_1
(Option.map
(fun (request : Httpaf.Request.t) ->
(fun (request : Httpun.Request.t) ->
Versions.HTTP.Raw.to_version_exn request.version)
request))
~error_handler
Expand All @@ -178,25 +178,25 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
(error :> Error.server)

let make_request_handler ~sw ~config ~fd handler :
Eio.Net.Sockaddr.stream -> Httpaf.Reqd.t Gluten.reqd -> unit
Eio.Net.Sockaddr.stream -> Httpun.Reqd.t Gluten.reqd -> unit
=
fun client_addr reqd ->
let { Gluten.reqd; upgrade } = reqd in
let arg =
let request = Httpaf.Reqd.request reqd in
let request = Httpun.Reqd.request reqd in
let request_body =
let body_length = Httpaf.Request.body_length request in
let body_length = Httpun.Request.body_length request in
Piaf_body.Raw.to_request_body
(module Body.Reader : Piaf_body.Raw.Reader
with type t = Httpaf.Body.Reader.t)
with type t = Httpun.Body.Reader.t)
~body_length:(body_length :> Piaf_body.length)
~on_eof:(fun t ->
Option.iter
(fun error ->
t.error_received :=
Promise.create_resolved (error :> Error.t))
(Httpaf.Reqd.error_code reqd))
(Httpaf.Reqd.request_body reqd)
(Httpun.Reqd.error_code reqd))
(Httpun.Reqd.request_body reqd)
in
{ Server_intf.Handler.ctx =
{ Request_info.client_address = client_addr
Expand Down
Loading