Skip to content

Commit

Permalink
http: add Request.make
Browse files Browse the repository at this point in the history
Add `Request.make` so that we don't have to adorn `[@warning "-3"]` when
creating `Request.t`.
  • Loading branch information
bikallem committed Jun 9, 2022
1 parent 0a586d7 commit 5a1b6a9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
14 changes: 7 additions & 7 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
## Unreleased
- Remove unused values to help ci(@bikallem #873)
- http: add Http.Request.make (@bikallem #878)
- New curl based clients (@rgrinberg #813)
+ cohttp-curl-lwt for an Lwt backend
+ cohttp-curl-async for an Async backend
- Completely new Parsing layers for servers (@anuragsoni #819)
+ Cohttp now uses an optimized parser for requests.
+ The new parser produces much less temporary buffers during read operations in servers.
+ The new parser produces much less temporary buffers during read operations
in servers.
- Faster header comparison (gasche #818)
- Introduce http package containing common signatures and structures useful for compatibility with cohttp - and no dependencies (rgrinberg #812)
- Faster Request/Response comparison (rgrinberg #814)
- Use raise_notrace in header short circuiting exceptions (rgrinberg #802)
- Introduce http package containing common signatures and structures useful for
compatibility with cohttp - and no dependencies (rgrinberg #812)
- async(server): allow reading number of active connections (anuragsoni #809)
- Various internal refactors (rgrinberg, mseri #820, #800, #799, #797)
- Various internal refactors (rgrinberg, mseri, #802, #812, #820, #800, #799,
#797)
- http (all cohttp server backends): Consider the connection header in response
in addition to the request when deciding on whether to keep a connection
alive (anuragsoni, #843)
Expand All @@ -27,7 +28,6 @@
async TCP server using the Tcp module from `Async_unix` and lets the user
have more control over how the `Reader.t` and `Writer.t` are created.
- http(header): faster `to_lines` and `to_frames` implementation (mseri #847)
- ci: add changelog check (mseri #850)
- cohttp(cookies): use case-insensitive comparison to check for `set-cookies` (mseri #858)
- New lwt based server implementation: cohttp-server-lwt-unix
+ This new implementation does not depend on conduit and has a simpler and
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ interoperate with Cohttp.")
(ppx_here :with-test)
(core (and :with-test (>= v0.13.0)))
(core_bench :with-test)
(crowbar :with-test)
(crowbar (and :with-test (>= 0.2)))
(sexplib0 :with-test)))

(package
Expand Down
2 changes: 1 addition & 1 deletion http.opam
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ depends: [
"ppx_here" {with-test}
"core" {with-test & >= "v0.13.0"}
"core_bench" {with-test}
"crowbar" {with-test}
"crowbar" {with-test & >= "0.2"}
"sexplib0" {with-test}
"odoc" {with-doc}
]
Expand Down
16 changes: 10 additions & 6 deletions http/src/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,15 @@ module Request = struct
| `GET | `HEAD | `CONNECT | `TRACE -> `No
| `DELETE | `POST | `PUT | `PATCH | `OPTIONS | `Other _ ->
Transfer.has_body req.encoding

let make ?(meth = `GET) ?(version = `HTTP_1_1) ?(encoding = Transfer.Chunked)
?(headers = Header.empty) ?scheme resource =
let encoding =
match Header.get_transfer_encoding headers with
| Transfer.(Chunked | Fixed _) as enc -> enc
| Unknown -> encoding
in
{ headers; meth; scheme; resource; version; encoding }
end

module Response = struct
Expand All @@ -781,12 +790,7 @@ module Response = struct
| i -> i

let make ?(version = `HTTP_1_1) ?(status = `OK) ?(flush = false)
?(encoding = Transfer.Chunked) ?(headers = Header.empty) () =
let encoding =
match Header.get_transfer_encoding headers with
| Transfer.(Chunked | Fixed _) as enc -> enc
| Unknown -> encoding
in
?(encoding = Transfer.Unknown) ?(headers = Header.empty) () =
{ encoding; headers; version; flush; status }

let headers t = t.headers
Expand Down
17 changes: 17 additions & 0 deletions http/src/http.mli
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,23 @@ module Request : sig

val is_keep_alive : t -> bool
(** Return true whether the connection should be reused *)

val make :
?meth:Method.t ->
?version:Version.t ->
?encoding:Transfer.encoding ->
?headers:Header.t ->
?scheme:string ->
string ->
t
(** [make resource] is [t]. The default values if not specified are as
follows:
- [meth] is [`GET]
- [version] is [`HTTP_1_1]
- [headers] is [Header.empty]
- [encoding] is [Transfer.Chunked]
- [scheme] is [None] *)
end

module Response : sig
Expand Down

0 comments on commit 5a1b6a9

Please sign in to comment.