Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Jan 5, 2025
1 parent 31c2558 commit e7f2f8a
Show file tree
Hide file tree
Showing 19 changed files with 315 additions and 324 deletions.
112 changes: 56 additions & 56 deletions bin/carl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ let inflate response_body =
Buffer.contents result_buf

let handle_response
~cli
~sw
~(stdout : _ Eio_unix.sink)
({ Response.body; _ } as response)
~cli
~sw
~(stdout : _ Eio_unix.sink)
({ Response.body; _ } as response)
=
let open Util.Result.Syntax in
let { head; compressed; include_; _ } = cli in
Expand Down Expand Up @@ -321,7 +321,7 @@ let handle_response
result

let build_headers
~cli:{ headers; user_agent; referer; compressed; oauth2_bearer; user; _ }
~cli:{ headers; user_agent; referer; compressed; oauth2_bearer; user; _ }
=
let headers = ("User-Agent", user_agent) :: headers in
let headers =
Expand Down Expand Up @@ -420,21 +420,21 @@ let log_level_of_list ~silent = function
| _ -> Some Debug

let piaf_config_of_cli
{ follow_redirects
; max_redirects
; max_http_version
; h2c_upgrade
; http2_prior_knowledge
; cacert
; capath
; insecure
; min_tls_version
; max_tls_version
; connect_timeout
; data
; head
; _
}
{ follow_redirects
; max_redirects
; max_http_version
; h2c_upgrade
; http2_prior_knowledge
; cacert
; capath
; insecure
; min_tls_version
; max_tls_version
; connect_timeout
; data
; head
; _
}
=
match data, head with
| Some _, true ->
Expand Down Expand Up @@ -476,7 +476,7 @@ let main ({ log_level; urls; _ } as cli) =
* --retry-connrefused Retry on connection refused (use with --retry)
* --retry-delay <seconds> Wait time between retries
* --retry-max-time <seconds> Retry only within this period
*)
*)
module CLI = struct
let request =
let request_conv =
Expand Down Expand Up @@ -688,41 +688,41 @@ module CLI = struct
Arg.(non_empty & pos_all string [] & info [] ~docv)

let parse
cacert
capath
cert
compressed
connect_timeout
data
default_proto
head
headers
include_
insecure
key
follow_redirects
max_redirects
request
use_http_1_0
use_http_1_1
use_http_2
http2_prior_knowledge
referer
sslv3
tlsv1
tlsv1_0
tlsv1_1
tlsv1_2
tlsv1_3
max_tls_version
upload_file
user_agent
user
oauth2_bearer
silent
verbose
output
urls
cacert
capath
cert
compressed
connect_timeout
data
default_proto
head
headers
include_
insecure
key
follow_redirects
max_redirects
request
use_http_1_0
use_http_1_1
use_http_2
http2_prior_knowledge
referer
sslv3
tlsv1
tlsv1_0
tlsv1_1
tlsv1_2
tlsv1_3
max_tls_version
upload_file
user_agent
user
oauth2_bearer
silent
verbose
output
urls
=
{ follow_redirects
; max_redirects
Expand Down
5 changes: 1 addition & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

inputs.nix-filter.url = "github:numtide/nix-filter";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs = {
url = "github:nix-ocaml/nix-overlays";
inputs.flake-utils.follows = "flake-utils";
};
inputs.nixpkgs.url = "github:nix-ocaml/nix-overlays";

outputs = { self, nixpkgs, flake-utils, nix-filter }:
flake-utils.lib.eachDefaultSystem (system:
Expand Down
88 changes: 45 additions & 43 deletions lib/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ let create_http_connection ~sw ~config ~conn_info ~uri fd =
| false, HTTP_2, true -> (module Http1.HTTP : Http_intf.HTTP), HTTP_1_1
| false, _, _ ->
let version =
if Versions.HTTP.Raw.(compare (of_version config.max_http_version) v2_0)
>= 0
if
Versions.HTTP.Raw.(compare (of_version config.max_http_version) v2_0)
>= 0
then Versions.HTTP.HTTP_1_1
else config.max_http_version
in
Expand Down Expand Up @@ -94,9 +95,10 @@ let create_https_connection ~sw ~config ~conn_info ~uri fd =
then (module Http2.HTTPS : Http_intf.HTTPS), Versions.HTTP.HTTP_2
else
( (module Http1.HTTPS : Http_intf.HTTPS)
, if Versions.HTTP.Raw.(
compare (of_version config.max_http_version) v2_0)
>= 0
, if
Versions.HTTP.Raw.(
compare (of_version config.max_http_version) v2_0)
>= 0
then HTTP_1_1
else config.max_http_version )
in
Expand Down Expand Up @@ -168,13 +170,13 @@ let shutdown t = shutdown_conn t.conn

(* returns true if it succeeding in reusing the connection, false otherwise. *)
let reuse_or_set_up_new_connection
({ conn =
Connection.Conn
({ impl = (module Http); connection; config; info; _ } as conn)
; env
; _
} as t)
new_uri
({ conn =
Connection.Conn
({ impl = (module Http); connection; config; info; _ } as conn)
; env
; _
} as t)
new_uri
=
match Scheme.of_uri new_uri with
| Error _ as e -> e
Expand Down Expand Up @@ -244,19 +246,19 @@ type request_info =
}

let rec return_response
({ conn; sw; _ } as t)
({ request; _ } as request_info)
({ Response.status; headers; version; body } as response)
({ conn; sw; _ } as t)
({ request; _ } as request_info)
({ Response.status; headers; version; body } as response)
=
let (Connection.Conn
{ impl = (module Http)
; runtime
; info = { Connection_info.scheme; _ } as conn_info
; uri
; fd
; config
; _
})
{ impl = (module Http)
; runtime
; info = { Connection_info.scheme; _ } as conn_info
; uri
; fd
; config
; _
})
=
conn
in
Expand Down Expand Up @@ -311,12 +313,12 @@ let is_h2c_upgrade ~config ~version ~scheme =
| _ -> false

let make_request_info
{ conn = Connection.Conn { version; info; config; _ }; _ }
?(remaining_redirects = config.max_redirects)
~meth
~headers
~body
target
{ conn = Connection.Conn { version; info; config; _ }; _ }
?(remaining_redirects = config.max_redirects)
~meth
~headers
~body
target
=
let { Connection_info.host; scheme; _ } = info in
let is_h2c_upgrade = is_h2c_upgrade ~config ~version ~scheme in
Expand Down Expand Up @@ -352,8 +354,8 @@ let make_request_info
{ remaining_redirects; headers; request; meth; target; is_h2c_upgrade }

let rec send_request_and_handle_response
t
({ remaining_redirects; request; headers; meth; _ } as request_info)
t
({ remaining_redirects; request; headers; meth; _ } as request_info)
=
let { conn = Conn ({ info; uri; config; _ } as conn); _ } = t in

Expand Down Expand Up @@ -477,10 +479,10 @@ let patch t ?headers ?body target =
let delete t ?headers ?body target = call t ?headers ?body ~meth:`DELETE target

let ws_upgrade :
t
-> ?headers:(string * string) list
-> string
-> (Ws.Descriptor.t, [> Error.client ]) result
t
-> ?headers:(string * string) list
-> string
-> (Ws.Descriptor.t, [> Error.client ]) result
=
fun t ?(headers = []) target ->
let*! response =
Expand Down Expand Up @@ -508,15 +510,15 @@ module Oneshot = struct
* - HTTP/2 doesn't support the `Connection` header
* - We want to reuse the same connection in case there's a redirect we must
* follow
*)
*)
let call
?(config = Config.default)
?(headers = [])
?(body = Body.empty)
~sw
~meth
env
uri
?(config = Config.default)
?(headers = [])
?(body = Body.empty)
~sw
~meth
env
uri
=
let*! ({ conn = Connection.Conn conn; _ } as t) =
create ~config ~sw env uri
Expand Down
28 changes: 14 additions & 14 deletions lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,44 @@ module Logs = (val Logging.setup ~src:"piaf.config" ~doc:"Piaf Config module")
* - Retries
* - 8.1.4 in https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
* - set max content length on the server config
*)
*)

type t =
{ follow_redirects : bool (** whether to follow redirects *)
; max_redirects : int
(** max redirects to follow. Could probably be rolled up into one option *)
(** max redirects to follow. Could probably be rolled up into one option *)
; allow_insecure : bool
(** Wether to allow insecure server connections when using SSL *)
(** Wether to allow insecure server connections when using SSL *)
; max_http_version : Versions.HTTP.t
(** Use this as the highest HTTP version when sending requests *)
(** Use this as the highest HTTP version when sending requests *)
; h2c_upgrade : bool
(** Send an upgrade to `h2c` (HTTP/2 over TCP) request to the server.
(** Send an upgrade to `h2c` (HTTP/2 over TCP) request to the server.
`http2_prior_knowledge` below ignores this option. *)
; http2_prior_knowledge : bool
(** Assume HTTP/2 prior knowledge -- don't use HTTP/1.1 Upgrade when
(** Assume HTTP/2 prior knowledge -- don't use HTTP/1.1 Upgrade when
communicating with "http" URIs, default to HTTP/2.0 when we can't agree to
an ALPN protocol and communicating with "https" URIs. *)
; cacert : Cert.t option
(** Either the certificates string or path to a file with certificates to
(** Either the certificates string or path to a file with certificates to
verify peer. Both should be in PEM format *)
; capath : string option
(** The path to a directory which contains CA certificates in PEM format *)
(** The path to a directory which contains CA certificates in PEM format *)
; clientcert : (Cert.t * Cert.t) option
(** Client certificate in PEM format and private key *)
(** Client certificate in PEM format and private key *)
; min_tls_version : Versions.TLS.t
; max_tls_version : Versions.TLS.t
; tcp_nodelay : bool
; connect_timeout : float (* seconds *)
; (* Buffer sizes *)
buffer_size : int
(** Buffer size used for requests and responses. Defaults to 16384 bytes *)
(** Buffer size used for requests and responses. Defaults to 16384 bytes *)
; body_buffer_size : int
(** Buffer size used for request and response bodies. *)
(** Buffer size used for request and response bodies. *)
; enable_http2_server_push : bool
; default_headers : (Headers.name * Headers.value) list
(** Set default headers (on the client) to be sent on every request. *)
(** Set default headers (on the client) to be sent on every request. *)
; flush_headers_immediately : bool
(** Specifies whether to flush message headers to the transport immediately,
(** Specifies whether to flush message headers to the transport immediately,
or if Piaf should wait for the first body bytes to be written. Defaults to
[false]. *)
; prefer_ip_version : [ `V4 | `V6 | `Both ]
Expand Down Expand Up @@ -115,7 +115,7 @@ let to_http1_config { body_buffer_size; buffer_size; _ } =
}

let to_http2_config
{ enable_http2_server_push; body_buffer_size; buffer_size; _ }
{ enable_http2_server_push; body_buffer_size; buffer_size; _ }
=
let h2_default_buffer_size = H2.Config.default.read_buffer_size in
let buffer_size =
Expand Down
Loading

0 comments on commit e7f2f8a

Please sign in to comment.