Skip to content

Commit 73b16f0

Browse files
authored
Merge pull request #293 from mabiede/upgrade-packages
Upgrade packages, replace mirage-crypto hashes with digestif
2 parents b72c5d2 + 3ac92a6 commit 73b16f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+654
-618
lines changed

.ocamlformat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version = 0.19.0
21
profile = janestreet
32
parse-docstrings = true
43
wrap-comments = true

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
- Fix Fullsplat behavior (routes with `**`)
1313
- Undo splat reverse order. Now, the matches for `/*/*/*` with the url `/a/b/c` will return `["a"; "b"; "c"]`
14+
- deprecated `Term` commands
1415

1516
## Changed
1617

1718
- Update various opium-testing apis to avoid raising warning 16
19+
- replacing `mirage-crypto` with `digestif`, because `mirage-crypto` doesn't provide `md5` and `sha1` anymore
1820

1921
# 0.20.0
2022

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ $ dune build example/simple_middleware/main.ml
190190
```
191191

192192
Here we also use the ability of Opium to generate a cmdliner term to run your
193-
app. Run your executable with `--help` to see the options that are available to you.
193+
app. Run your executable with `-h` to see the options that are available to you.
194194
For example:
195195

196196
```sh-session
197197
# run in debug mode on port 9000
198-
$ dune exec example/simple_middleware/main.exe -- -p 9000 -d
198+
$ dune exec dune build example/simple_middleware/main.exe -- -p 9000 -d
199199
```

benchmark/src/httpaf.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ let benchmark =
4747
let error_handler ?request:_ error start_response =
4848
let response_body = start_response Headers.empty in
4949
(match error with
50-
| `Exn exn ->
51-
Body.write_string response_body (Printexc.to_string exn);
52-
Body.write_string response_body "\n"
53-
| #Status.standard as error ->
54-
Body.write_string response_body (Status.default_reason_phrase error));
50+
| `Exn exn ->
51+
Body.write_string response_body (Printexc.to_string exn);
52+
Body.write_string response_body "\n"
53+
| #Status.standard as error ->
54+
Body.write_string response_body (Status.default_reason_phrase error));
5555
Body.close_writer response_body
5656
;;
5757

@@ -61,11 +61,11 @@ let () =
6161
let request_handler _ = benchmark in
6262
let error_handler _ = error_handler in
6363
Lwt.async (fun () ->
64-
Lwt_io.establish_server_with_client_socket
65-
~backlog:11_000
66-
listen_address
67-
(Server.create_connection_handler ~request_handler ~error_handler)
68-
>>= fun _server -> Lwt.return_unit);
64+
Lwt_io.establish_server_with_client_socket
65+
~backlog:11_000
66+
listen_address
67+
(Server.create_connection_handler ~request_handler ~error_handler)
68+
>>= fun _server -> Lwt.return_unit);
6969
let forever, _ = Lwt.wait () in
7070
Lwt_main.run forever
7171
;;

dune-project

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
(package
1919
(name rock)
2020
(synopsis
21-
"Minimalist framework to build extensible HTTP servers and clients")
21+
"Minimalist framework to build extensible HTTP servers and clients")
2222
(description
23-
"Rock is a Unix indpendent API to build extensible HTTP servers and clients. It provides building blocks such as middlewares and handlers (a.k.a controllers).")
23+
"Rock is a Unix indpendent API to build extensible HTTP servers and clients. It provides building blocks such as middlewares and handlers (a.k.a controllers).")
2424
(depends
2525
(ocaml
2626
(>= 4.08))
@@ -37,7 +37,7 @@
3737
(name opium)
3838
(synopsis "OCaml web framework")
3939
(description
40-
"Opium is a web framework for OCaml that provides everything you need to build safe, fast and extensible web applications.")
40+
"Opium is a web framework for OCaml that provides everything you need to build safe, fast and extensible web applications.")
4141
(depends
4242
(ocaml
4343
(>= 4.08))
@@ -54,7 +54,7 @@
5454
magic-mime
5555
yojson
5656
tyxml
57-
mirage-crypto
57+
digestif
5858
(base64
5959
(>= 3.0.0))
6060
astring
@@ -71,7 +71,7 @@
7171
(name opium-testing)
7272
(synopsis "Testing library for Opium")
7373
(description
74-
"A library that provides helpers to easily test your Opium applications.")
74+
"A library that provides helpers to easily test your Opium applications.")
7575
(depends
7676
(ocaml
7777
(>= 4.08))
@@ -85,7 +85,7 @@
8585
(name opium-graphql)
8686
(synopsis "Run GraphQL servers with Opium")
8787
(description
88-
"This package allows you to execute Opium requests against GraphQL schemas built with `graphql`.")
88+
"This package allows you to execute Opium requests against GraphQL schemas built with `graphql`.")
8989
(depends
9090
(ocaml
9191
(>= 4.08))

example/file_upload/main.ml

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -32,76 +32,76 @@ let index_view ?(success = false) () =
3232
layout
3333
~title:"Opium file upload"
3434
[ (if success
35-
then
36-
div
37-
~a:[ a_class [ "mx-auto mt-16 max-w-lg rounded-md bg-green-50 p-4" ] ]
38-
[ div
39-
~a:[ a_class [ "flex" ] ]
40-
[ div
41-
~a:[ a_class [ "flex-shrink-0" ] ]
42-
[ svg
43-
~a:
44-
[ Tyxml.Svg.a_class [ "h-5 w-5 text-green-400" ]
45-
; Tyxml.Svg.a_viewBox (0., 0., 20., 20.)
46-
; Tyxml.Svg.a_fill `CurrentColor
47-
]
48-
[ Tyxml.Svg.path
49-
~a:
50-
[ a_svg_custom "fill-rule" "evenodd"
51-
; Tyxml.Svg.a_d
52-
"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 \
53-
00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 \
54-
1.414l2 2a1 1 0 001.414 0l4-4z"
55-
; a_svg_custom "clip-rule" "evenodd"
56-
]
57-
[]
58-
]
59-
]
60-
; div
61-
~a:[ a_class [ "ml-3" ] ]
62-
[ p
63-
~a:[ a_class [ "text-sm leading-5 font-medium text-green-800" ] ]
64-
[ txt "Successfully uploaded" ]
65-
]
66-
; div
67-
~a:[ a_class [ "ml-auto pl-3" ] ]
68-
[ div
69-
~a:[ a_class [ "-mx-1.5 -my-1.5" ] ]
70-
[ button
71-
~a:
72-
[ a_class
73-
[ "inline-flex rounded-md p-1.5 text-green-500 \
74-
hover:bg-green-100 focus:outline-none \
75-
focus:bg-green-100 transition ease-in-out \
76-
duration-150"
77-
]
78-
; a_aria "label" [ "Dismiss" ]
79-
]
80-
[ svg
81-
~a:
82-
[ Tyxml.Svg.a_class [ "h-5 w-5" ]
83-
; Tyxml.Svg.a_viewBox (0., 0., 20., 20.)
84-
; Tyxml.Svg.a_fill `CurrentColor
85-
]
86-
[ Tyxml.Svg.path
87-
~a:
88-
[ a_svg_custom "fill-rule" "evenodd"
89-
; Tyxml.Svg.a_d
90-
"M4.293 4.293a1 1 0 011.414 0L10 \
91-
8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 \
92-
10l4.293 4.293a1 1 0 01-1.414 1.414L10 \
93-
11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 \
94-
10 4.293 5.707a1 1 0 010-1.414z"
95-
; a_svg_custom "clip-rule" "evenodd"
96-
]
97-
[]
98-
]
99-
]
100-
]
101-
]
102-
]
103-
]
104-
else div [])
35+
then
36+
div
37+
~a:[ a_class [ "mx-auto mt-16 max-w-lg rounded-md bg-green-50 p-4" ] ]
38+
[ div
39+
~a:[ a_class [ "flex" ] ]
40+
[ div
41+
~a:[ a_class [ "flex-shrink-0" ] ]
42+
[ svg
43+
~a:
44+
[ Tyxml.Svg.a_class [ "h-5 w-5 text-green-400" ]
45+
; Tyxml.Svg.a_viewBox (0., 0., 20., 20.)
46+
; Tyxml.Svg.a_fill `CurrentColor
47+
]
48+
[ Tyxml.Svg.path
49+
~a:
50+
[ a_svg_custom "fill-rule" "evenodd"
51+
; Tyxml.Svg.a_d
52+
"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 \
53+
00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 \
54+
1.414l2 2a1 1 0 001.414 0l4-4z"
55+
; a_svg_custom "clip-rule" "evenodd"
56+
]
57+
[]
58+
]
59+
]
60+
; div
61+
~a:[ a_class [ "ml-3" ] ]
62+
[ p
63+
~a:[ a_class [ "text-sm leading-5 font-medium text-green-800" ] ]
64+
[ txt "Successfully uploaded" ]
65+
]
66+
; div
67+
~a:[ a_class [ "ml-auto pl-3" ] ]
68+
[ div
69+
~a:[ a_class [ "-mx-1.5 -my-1.5" ] ]
70+
[ button
71+
~a:
72+
[ a_class
73+
[ "inline-flex rounded-md p-1.5 text-green-500 \
74+
hover:bg-green-100 focus:outline-none \
75+
focus:bg-green-100 transition ease-in-out \
76+
duration-150"
77+
]
78+
; a_aria "label" [ "Dismiss" ]
79+
]
80+
[ svg
81+
~a:
82+
[ Tyxml.Svg.a_class [ "h-5 w-5" ]
83+
; Tyxml.Svg.a_viewBox (0., 0., 20., 20.)
84+
; Tyxml.Svg.a_fill `CurrentColor
85+
]
86+
[ Tyxml.Svg.path
87+
~a:
88+
[ a_svg_custom "fill-rule" "evenodd"
89+
; Tyxml.Svg.a_d
90+
"M4.293 4.293a1 1 0 011.414 0L10 \
91+
8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 \
92+
10l4.293 4.293a1 1 0 01-1.414 1.414L10 \
93+
11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 \
94+
10 4.293 5.707a1 1 0 010-1.414z"
95+
; a_svg_custom "clip-rule" "evenodd"
96+
]
97+
[]
98+
]
99+
]
100+
]
101+
]
102+
]
103+
]
104+
else div [])
105105
; form
106106
~a:[ a_enctype "multipart/form-data"; a_action "/upload"; a_method `Post ]
107107
[ div

example/graphql/main.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ module Schema = struct
2929

3030
let user : (context, user option) Graphql_lwt.Schema.typ =
3131
Schema.(
32-
obj "user" ~doc:"A user in the system" ~fields:(fun _ ->
32+
obj
33+
"user"
34+
~doc:"A user in the system"
35+
~fields:
3336
[ field
3437
"id"
3538
~doc:"Unique user identifier"
@@ -46,7 +49,7 @@ module Schema = struct
4649
~typ:(non_null role)
4750
~args:Arg.[]
4851
~resolve:(fun _info p -> p.role)
49-
]))
52+
])
5053
;;
5154

5255
let schema =

example/rock_server/main.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ let run () =
5959
fd
6060
in
6161
Lwt.async (fun () ->
62-
let* _ =
63-
Lwt_io.establish_server_with_client_socket listen_address connection_handler
64-
in
65-
Lwt.return_unit);
62+
let* _ =
63+
Lwt_io.establish_server_with_client_socket listen_address connection_handler
64+
in
65+
Lwt.return_unit);
6666
let forever, _ = Lwt.wait () in
6767
Lwt_main.run forever
6868
;;

opium-graphql/src/opium_graphql.ml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,24 @@ let execute_request schema ctx req =
107107
| Ok (query, variables, operation_name) ->
108108
let+ result = execute_query ctx schema variables operation_name query in
109109
(match result with
110-
| Ok (`Response data) -> data |> basic_to_safe |> Opium.Response.of_json ~status:`OK
111-
| Ok (`Stream stream) ->
112-
Graphql_lwt.Schema.Io.Stream.close stream;
113-
let body = "Subscriptions are only supported via websocket transport" in
114-
Opium.Response.of_plain_text ~status:`Bad_request body
115-
| Error err -> err |> basic_to_safe |> Opium.Response.of_json ~status:`Bad_request)
110+
| Ok (`Response data) -> data |> basic_to_safe |> Opium.Response.of_json ~status:`OK
111+
| Ok (`Stream stream) ->
112+
Graphql_lwt.Schema.Io.Stream.close stream;
113+
let body = "Subscriptions are only supported via websocket transport" in
114+
Opium.Response.of_plain_text ~status:`Bad_request body
115+
| Error err -> err |> basic_to_safe |> Opium.Response.of_json ~status:`Bad_request)
116116
;;
117117

118118
let make_handler
119-
: type a.
120-
make_context:(Rock.Request.t -> a) -> a Graphql_lwt.Schema.schema -> Rock.Handler.t
119+
: type a.
120+
make_context:(Rock.Request.t -> a) -> a Graphql_lwt.Schema.schema -> Rock.Handler.t
121121
=
122-
fun ~make_context schema req ->
122+
fun ~make_context schema req ->
123123
match req.Opium.Request.meth with
124124
| `GET ->
125-
if Httpaf.Headers.get req.Opium.Request.headers "Connection" = Some "Upgrade"
126-
&& Httpaf.Headers.get req.Opium.Request.headers "Upgrade" = Some "websocket"
125+
if
126+
Httpaf.Headers.get req.Opium.Request.headers "Connection" = Some "Upgrade"
127+
&& Httpaf.Headers.get req.Opium.Request.headers "Upgrade" = Some "websocket"
127128
then
128129
(* TODO: Add subscription support when there is a good solution for websockets with
129130
Httpaf *)
@@ -139,9 +140,8 @@ let make_handler
139140
let graphiql_etag =
140141
Asset.read "graphiql.html"
141142
|> Option.get
142-
|> Cstruct.of_string
143-
|> Mirage_crypto.Hash.digest `MD5
144-
|> Cstruct.to_string
143+
|> Digestif.MD5.digest_string
144+
|> Digestif.MD5.to_raw_string
145145
|> Base64.encode_exn
146146
;;
147147

@@ -156,12 +156,12 @@ let make_graphiql_handler ~graphql_endpoint req =
156156
~etag:graphiql_etag
157157
~mime_type:"text/html; charset=utf-8"
158158
(fun () ->
159-
match Asset.read "graphiql.html" with
160-
| None -> Lwt.return_error `Internal_server_error
161-
| Some body ->
162-
let regexp = Str.regexp_string "%%GRAPHQL_API%%" in
163-
let body = Str.global_replace regexp graphql_endpoint body in
164-
Lwt.return_ok (Opium.Body.of_string body))
159+
match Asset.read "graphiql.html" with
160+
| None -> Lwt.return_error `Internal_server_error
161+
| Some body ->
162+
let regexp = Str.regexp_string "%%GRAPHQL_API%%" in
163+
let body = Str.global_replace regexp graphql_endpoint body in
164+
Lwt.return_ok (Opium.Body.of_string body))
165165
in
166166
if accept_html
167167
then h req

0 commit comments

Comments
 (0)