Skip to content

Commit

Permalink
Upgrade to upstream dream
Browse files Browse the repository at this point in the history
  • Loading branch information
tmattio committed Feb 2, 2022
1 parent dde4204 commit 5465b23
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
7 changes: 6 additions & 1 deletion dream-encoding.opam
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ build: [
dev-repo: "git+https://github.com/tmattio/dream-encoding.git"
conflicts: [
"result" {< "1.5"} # Might use result through lwt and explicitly uses Result.bind
]
]
pin-depends: [
["dream.dev" "git+https://github.com/aantron/dream#master"]
["dream-pure.dev" "git+https://github.com/aantron/dream#master"]
["dream-httpaf.dev" "git+https://github.com/aantron/dream#master"]
]
7 changes: 6 additions & 1 deletion dream-encoding.opam.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
conflicts: [
"result" {< "1.5"} # Might use result through lwt and explicitly uses Result.bind
]
]
pin-depends: [
["dream.dev" "git+https://github.com/aantron/dream#master"]
["dream-pure.dev" "git+https://github.com/aantron/dream#master"]
["dream-httpaf.dev" "git+https://github.com/aantron/dream#master"]
]
4 changes: 0 additions & 4 deletions dune

This file was deleted.

2 changes: 1 addition & 1 deletion example/server.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(** Main entry point for our application. *)

let () =
Dream.run ~debug:true
Dream.run
@@ Dream.logger
@@ Dream_encoding.compress
@@ Dream.router [ Dream.get "/" (fun _ -> Dream.html "Hello World!") ]
Expand Down
18 changes: 5 additions & 13 deletions lib/dream_encoding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ let encoding_of_string = function
`Unknown s

let content_encodings request =
match Dream.header "content-encoding" request with
match Dream.header request "content-encoding" with
| None ->
None
| Some s ->
Expand All @@ -119,7 +119,7 @@ let content_encodings request =
|> Option.some

let accepted_encodings_with_weights request =
match Dream.header "accept-encoding" request with
match Dream.header request "accept-encoding" with
| None ->
None
| Some s ->
Expand Down Expand Up @@ -177,9 +177,9 @@ let with_encoded_body ?(algorithm = `Deflate) body response =
response
| _ ->
let encoded_body = deflate_string ~algorithm body in
Dream.set_body response encoded_body;
Dream.set_header response "Content-Encoding" (algorithm_to_string algorithm);
response
|> Dream.with_body encoded_body
|> Dream.with_header "Content-Encoding" (algorithm_to_string algorithm)

let compress handler req =
let%lwt response = handler req in
Expand All @@ -194,14 +194,6 @@ let compress handler req =
let%lwt body = Dream.body response in
Lwt.return @@ with_encoded_body ~algorithm body response

let request_with_body body request =
let client = Dream.client request in
let method_ = Dream.method_ request in
let target = Dream.target request in
let version = Dream.version request in
let headers = Dream.all_headers request in
Dream.request ~client ~method_ ~target ~version ~headers body

let decompress handler req =
let rec aux algorithms content =
match algorithms with
Expand All @@ -221,7 +213,7 @@ let decompress handler req =
let body = aux algorithms body in
(match body with
| Ok body ->
let req = request_with_body body req in
Dream.set_body req body;
handler req
| Error (`Msg err) ->
Dream.respond ~status:`Unsupported_Media_Type err)

0 comments on commit 5465b23

Please sign in to comment.