Skip to content

Commit 70cb9f1

Browse files
committed
eio(client): define env type for Client
1 parent b300c71 commit 70cb9f1

File tree

5 files changed

+49
-28
lines changed

5 files changed

+49
-28
lines changed

.ocamlformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=0.21.0
1+
version=0.24.1
22
profile=conventional
33
break-infix=fit-or-vertical
44
parse-docstrings=true

cohttp-eio/examples/client1.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
open Eio
2+
open Cohttp_eio
3+
4+
let () =
5+
Eio_main.run @@ fun env ->
6+
Switch.run @@ fun sw ->
7+
let res =
8+
Client.get
9+
~headers:(Http.Header.of_list [ ("Accept", "application/json") ])
10+
env sw
11+
(`Tcp (Eio.Net.Ipaddr.V4.loopback, 8080))
12+
(Uri.of_string "/")
13+
in
14+
match Client.read_fixed res with Some b -> print_string b | None -> ()

cohttp-eio/src/body.ml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ let quoted_char =
7070

7171
(*-- qdtext = HTAB / SP /%x21 / %x23-5B / %x5D-7E / obs-text -- *)
7272
let qdtext = function
73-
| '\t' | ' ' | '\x21' | '\x23' .. '\x5B'
74-
| '\x5D' .. '\x7E' as c -> c
73+
| ('\t' | ' ' | '\x21' | '\x23' .. '\x5B' | '\x5D' .. '\x7E') as c -> c
7574
| c -> failwith (Printf.sprintf "Invalid quoted character %C" c)
7675

7776
(*-- quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE --*)
@@ -81,31 +80,35 @@ let quoted_string r =
8180
let rec aux () =
8281
match any_char r with
8382
| '"' -> Buffer.contents buf
84-
| '\\' -> Buffer.add_char buf (quoted_char r); aux ()
85-
| c -> Buffer.add_char buf (qdtext c); aux ()
83+
| '\\' ->
84+
Buffer.add_char buf (quoted_char r);
85+
aux ()
86+
| c ->
87+
Buffer.add_char buf (qdtext c);
88+
aux ()
8689
in
8790
aux ()
8891

8992
let optional c x r =
9093
let c2 = peek_char r in
91-
if Some c = c2 then (consume r 1; Some (x r))
94+
if Some c = c2 then (
95+
consume r 1;
96+
Some (x r))
9297
else None
9398

9499
(*-- https://datatracker.ietf.org/doc/html/rfc7230#section-4.1 --*)
95100
let chunk_ext_val =
96101
let* c = peek_char in
97-
match c with
98-
| Some '"' -> quoted_string
99-
| _ -> token
102+
match c with Some '"' -> quoted_string | _ -> token
100103

101104
let rec chunk_exts r =
102105
let c = peek_char r in
103106
match c with
104107
| Some ';' ->
105-
consume r 1;
106-
let name = token r in
107-
let value = optional '=' chunk_ext_val r in
108-
{ name; value } :: chunk_exts r
108+
consume r 1;
109+
let name = token r in
110+
let value = optional '=' chunk_ext_val r in
111+
{ name; value } :: chunk_exts r
109112
| _ -> []
110113

111114
let chunk_size =

cohttp-eio/src/client.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
module Buf_read = Eio.Buf_read
22

33
type response = Http.Response.t * Buf_read.t
4+
type env = < net : Eio.Net.t >
45

5-
type body_disallowed_call =
6+
type 'a body_disallowed_call =
67
?version:Http.Version.t ->
78
?headers:Http.Header.t ->
8-
Eio.Stdenv.t ->
9+
(< env ; .. > as 'a) ->
910
Eio.Switch.t ->
1011
Eio.Net.Sockaddr.stream ->
1112
Uri.t ->
1213
response
14+
(** [body_disallowed_call] denotes HTTP client calls where a request is not
15+
allowed to have a request body. *)
1316

14-
type body_allowed_call =
17+
type 'a body_allowed_call =
1518
?version:Http.Version.t ->
1619
?headers:Http.Header.t ->
1720
?body:Body.t ->
18-
Eio.Stdenv.t ->
21+
(< env ; .. > as 'a) ->
1922
Eio.Switch.t ->
2023
Eio.Net.Sockaddr.stream ->
2124
Uri.t ->

cohttp-eio/src/cohttp_eio.mli

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,24 @@ end
9595

9696
module Client : sig
9797
type response = Http.Response.t * Eio.Buf_read.t
98+
type env = < net : Eio.Net.t >
9899

99-
type body_disallowed_call =
100+
type 'a body_disallowed_call =
100101
?version:Http.Version.t ->
101102
?headers:Http.Header.t ->
102-
Eio.Stdenv.t ->
103+
(< env ; .. > as 'a) ->
103104
Eio.Switch.t ->
104105
Eio.Net.Sockaddr.stream ->
105106
Uri.t ->
106107
response
107108
(** [body_disallowed_call] denotes HTTP client calls where a request is not
108109
allowed to have a request body. *)
109110

110-
type body_allowed_call =
111+
type 'a body_allowed_call =
111112
?version:Http.Version.t ->
112113
?headers:Http.Header.t ->
113114
?body:Body.t ->
114-
Eio.Stdenv.t ->
115+
(< env ; .. > as 'a) ->
115116
Eio.Switch.t ->
116117
Eio.Net.Sockaddr.stream ->
117118
Uri.t ->
@@ -126,23 +127,23 @@ module Client : sig
126127
?version:Http.Version.t ->
127128
?headers:Http.Header.t ->
128129
?body:Body.t ->
129-
Eio.Stdenv.t ->
130+
< env ; .. > ->
130131
Eio.Switch.t ->
131132
Eio.Net.Sockaddr.stream ->
132133
Uri.t ->
133134
response
134135

135136
(** {1 HTTP Calls with Body Disallowed} *)
136137

137-
val get : body_disallowed_call
138-
val head : body_disallowed_call
139-
val delete : body_disallowed_call
138+
val get : 'a body_disallowed_call
139+
val head : 'a body_disallowed_call
140+
val delete : 'a body_disallowed_call
140141

141142
(** {1 HTTP Calls with Body Allowed} *)
142143

143-
val post : body_allowed_call
144-
val put : body_allowed_call
145-
val patch : body_allowed_call
144+
val post : 'a body_allowed_call
145+
val put : 'a body_allowed_call
146+
val patch : 'a body_allowed_call
146147

147148
(** {1 Response Body} *)
148149

0 commit comments

Comments
 (0)