HTTP types: headers, status codes, methods, bodies, MIME types
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Upgrade to ocamlformat 0.29.0; fix csvt/sexpt streaming; reformat

- Update .ocamlformat to 0.29.0 across all 591 files
- csvt: reuse single Buffer.t for field reads (no alloc per field)
- sexpt: Obj members decoded from stream into Dict, typed Variant GADT
- Reformat all source files for 0.29.0

+134 -134
+62 -62
lib/body.mli
··· 11 11 {2 Examples} 12 12 13 13 {[ 14 - (* Simple text body *) 15 - let body = Body.text "Hello, World!" 14 + (* Simple text body *) 15 + let body = Body.text "Hello, World!" 16 16 17 - (* JSON body *) 18 - let body = Body.json {|{"name": "Alice", "age": 30}|} 17 + (* JSON body *) 18 + let body = Body.json {|{"name": "Alice", "age": 30}|} 19 19 20 - (* Form data *) 21 - let body = Body.form [ ("username", "alice"); ("password", "secret") ] 20 + (* Form data *) 21 + let body = Body.form [ ("username", "alice"); ("password", "secret") ] 22 22 23 - (* File upload *) 24 - let body = Body.of_file ~mime:Mime.pdf Eio.Path.(fs / "document.pdf") 23 + (* File upload *) 24 + let body = Body.of_file ~mime:Mime.pdf Eio.Path.(fs / "document.pdf") 25 25 26 - (* Multipart form with file *) 27 - let body = 28 - Body.multipart 29 - [ 30 - { 31 - name = "field"; 32 - filename = None; 33 - content_type = Mime.text_plain; 34 - content = `String "value"; 35 - }; 36 - { 37 - name = "file"; 38 - filename = Some "photo.jpg"; 39 - content_type = Mime.jpeg; 40 - content = `File Eio.Path.(fs / "photo.jpg"); 41 - }; 42 - ] 26 + (* Multipart form with file *) 27 + let body = 28 + Body.multipart 29 + [ 30 + { 31 + name = "field"; 32 + filename = None; 33 + content_type = Mime.text_plain; 34 + content = `String "value"; 35 + }; 36 + { 37 + name = "file"; 38 + filename = Some "photo.jpg"; 39 + content_type = Mime.jpeg; 40 + content = `File Eio.Path.(fs / "photo.jpg"); 41 + }; 42 + ] 43 43 ]} *) 44 44 45 45 val src : Logs.Src.t ··· 80 80 81 81 Example: 82 82 {[ 83 - let body = 84 - Body.json 85 - (Jsont.Object 86 - ( [ 87 - ("status", Jsont.String "success"); 88 - ("count", Jsont.Number 42.); 89 - ( "items", 90 - Jsont.Array 91 - ( [ Jsont.String "first"; Jsont.String "second" ], 92 - Jsont.Meta.none ) ); 93 - ], 94 - Jsont.Meta.none )) 83 + let body = 84 + Body.json 85 + (Jsont.Object 86 + ( [ 87 + ("status", Jsont.String "success"); 88 + ("count", Jsont.Number 42.); 89 + ( "items", 90 + Jsont.Array 91 + ( [ Jsont.String "first"; Jsont.String "second" ], 92 + Jsont.Meta.none ) ); 93 + ], 94 + Jsont.Meta.none )) 95 95 ]} *) 96 96 97 97 val jsonv : 'a Jsont.t -> 'a -> t ··· 104 104 105 105 Example: 106 106 {[ 107 - (* Define a codec for your type *) 108 - type user = { name : string; age : int } 107 + (* Define a codec for your type *) 108 + type user = { name : string; age : int } 109 109 110 - let user_codec = 111 - Jsont.Obj.map ~kind:"user" (fun name age -> { name; age }) 112 - |> Jsont.Obj.mem "name" Jsont.string ~enc:(fun u -> u.name) 113 - |> Jsont.Obj.mem "age" Jsont.int ~enc:(fun u -> u.age) 114 - |> Jsont.Obj.finish 110 + let user_codec = 111 + Jsont.Obj.map ~kind:"user" (fun name age -> { name; age }) 112 + |> Jsont.Obj.mem "name" Jsont.string ~enc:(fun u -> u.name) 113 + |> Jsont.Obj.mem "age" Jsont.int ~enc:(fun u -> u.age) 114 + |> Jsont.Obj.finish 115 115 116 - (* Create a JSON body from a typed value *) 117 - let body = Body.jsonv user_codec { name = "Alice"; age = 30 } 116 + (* Create a JSON body from a typed value *) 117 + let body = Body.jsonv user_codec { name = "Alice"; age = 30 } 118 118 ]} 119 119 120 120 @raise Eio.Io with {!Error.Json_encode_error} if encoding fails. *) ··· 159 159 160 160 Example: 161 161 {[ 162 - let body = 163 - Body.multipart 164 - [ 165 - { 166 - name = "username"; 167 - filename = None; 168 - content_type = Mime.text_plain; 169 - content = `String "alice"; 170 - }; 171 - { 172 - name = "avatar"; 173 - filename = Some "photo.jpg"; 174 - content_type = Mime.jpeg; 175 - content = `File Eio.Path.(fs / "photo.jpg"); 176 - }; 177 - ] 162 + let body = 163 + Body.multipart 164 + [ 165 + { 166 + name = "username"; 167 + filename = None; 168 + content_type = Mime.text_plain; 169 + content = `String "alice"; 170 + }; 171 + { 172 + name = "avatar"; 173 + filename = Some "photo.jpg"; 174 + content_type = Mime.jpeg; 175 + content = `File Eio.Path.(fs / "photo.jpg"); 176 + }; 177 + ] 178 178 ]} *) 179 179 180 180 (** {1 Properties} *)
+6 -6
lib/cache_control.mli
··· 14 14 {2 Examples} 15 15 16 16 {[ 17 - (* Parse response Cache-Control *) 18 - let cc = Cache_control.parse_response "max-age=3600, public" in 19 - Printf.printf "Max age: %d\n" (Option.get cc.max_age); 17 + (* Parse response Cache-Control *) 18 + let cc = Cache_control.parse_response "max-age=3600, public" in 19 + Printf.printf "Max age: %d\n" (Option.get cc.max_age); 20 20 21 - (* Check if cacheable *) 22 - if Cache_control.is_cacheable ~response_cc:cc ~status:200 then 23 - Printf.printf "Response is cacheable\n" 21 + (* Check if cacheable *) 22 + if Cache_control.is_cacheable ~response_cc:cc ~status:200 then 23 + Printf.printf "Response is cacheable\n" 24 24 ]} *) 25 25 26 26 val src : Logs.Src.t
+15 -15
lib/error.mli
··· 13 13 14 14 Errors are raised using the Eio.Io pattern: 15 15 {[ 16 - raise 17 - (Error.err 18 - (Error.Timeout { operation = "connect"; duration = Some 30.0 })) 16 + raise 17 + (Error.err 18 + (Error.Timeout { operation = "connect"; duration = Some 30.0 })) 19 19 ]} 20 20 21 21 To catch and handle errors: ··· 217 217 218 218 Example: 219 219 {[ 220 - (* Instead of: *) 220 + (* Instead of: *) 221 + raise 222 + (err (Invalid_request { reason = "missing host" })) 223 + (* Use: *) 221 224 raise 222 - (err (Invalid_request { reason = "missing host" })) 223 - (* Use: *) 224 - raise 225 - (invalid_request ~reason:"missing host") 225 + (invalid_request ~reason:"missing host") 226 226 ]} *) 227 227 228 228 val invalid_request : reason:string -> exn ··· 262 262 263 263 Example: 264 264 {[ 265 - (* Instead of: *) 265 + (* Instead of: *) 266 + raise 267 + (Error.err 268 + (Error.Invalid_request 269 + { reason = Fmt.str "Invalid status code: %s" code_str })) 270 + (* Use: *) 266 271 raise 267 - (Error.err 268 - (Error.Invalid_request 269 - { reason = Fmt.str "Invalid status code: %s" code_str })) 270 - (* Use: *) 271 - raise 272 - (Error.invalid_requestf "Invalid status code: %s" code_str) 272 + (Error.invalid_requestf "Invalid status code: %s" code_str) 273 273 ]} *) 274 274 275 275 val invalid_requestf : ('a, Format.formatter, unit, exn) format4 -> 'a
+7 -7
lib/expect_continue.mli
··· 13 13 14 14 The simplest way to configure 100-continue is with the polymorphic variant: 15 15 {[ 16 - (* Use 100-continue for bodies >= 1MB (default) *) 17 - let session = 18 - Requests.v ~sw ~expect_100_continue:(`Threshold 1_048_576L) env 16 + (* Use 100-continue for bodies >= 1MB (default) *) 17 + let session = 18 + Requests.v ~sw ~expect_100_continue:(`Threshold 1_048_576L) env 19 19 20 - (* Always use 100-continue *) 21 - let session = Requests.v ~sw ~expect_100_continue:`Always env 20 + (* Always use 100-continue *) 21 + let session = Requests.v ~sw ~expect_100_continue:`Always env 22 22 23 - (* Disable 100-continue *) 24 - let session = Requests.v ~sw ~expect_100_continue:`Disabled env 23 + (* Disable 100-continue *) 24 + let session = Requests.v ~sw ~expect_100_continue:`Disabled env 25 25 ]} *) 26 26 27 27 (** {1 Configuration Types} *)
+13 -13
lib/headers.mli
··· 19 19 for standard headers while allowing custom headers via [`Other]: 20 20 21 21 {[ 22 - let headers = 23 - Headers.empty 24 - |> Headers.set `Content_type "application/json" 25 - |> Headers.set `Authorization "Bearer token" 26 - |> Headers.set (`Other "X-Custom") "value" 22 + let headers = 23 + Headers.empty 24 + |> Headers.set `Content_type "application/json" 25 + |> Headers.set `Authorization "Bearer token" 26 + |> Headers.set (`Other "X-Custom") "value" 27 27 ]} 28 28 29 29 {2 Security} ··· 159 159 160 160 Examples: 161 161 {[ 162 - headers 163 - |> Headers.accept_language "en-US" headers 164 - |> Headers.accept_language "en-US, en;q=0.9, de;q=0.8" headers 165 - |> Headers.accept_language "*" 162 + headers 163 + |> Headers.accept_language "en-US" headers 164 + |> Headers.accept_language "en-US, en;q=0.9, de;q=0.8" headers 165 + |> Headers.accept_language "*" 166 166 ]} *) 167 167 168 168 val authorization : string -> t -> t ··· 427 427 428 428 Example: 429 429 {[ 430 - Headers.empty 431 - |> Headers.h2_request ~meth:"GET" ~scheme:"https" ~authority:"example.com" 432 - ~path:"/" 433 - |> Headers.set `Accept "application/json" 430 + Headers.empty 431 + |> Headers.h2_request ~meth:"GET" ~scheme:"https" ~authority:"example.com" 432 + ~path:"/" 433 + |> Headers.set `Accept "application/json" 434 434 ]} *) 435 435 436 436 (** {2 HTTP/2 Header Validation}
+3 -3
lib/http_date.mli
··· 22 22 23 23 Examples: 24 24 {[ 25 - parse "Sun, 06 Nov 1994 08:49:37 GMT" (* RFC 1123 *) parse 26 - "Sunday, 06-Nov-94 08:49:37 GMT" (* RFC 850 *) parse 27 - "Sun Nov 6 08:49:37 1994" (* asctime *) 25 + parse "Sun, 06 Nov 1994 08:49:37 GMT" (* RFC 1123 *) parse 26 + "Sunday, 06-Nov-94 08:49:37 GMT" (* RFC 850 *) parse 27 + "Sun Nov 6 08:49:37 1994" (* asctime *) 28 28 ]} *)
+2 -2
lib/http_version.mli
··· 76 76 77 77 Example: 78 78 {[ 79 - alpn_protocols ~preferred:[ Http_2; Http_1_1 ] 80 - (* Returns: ["h2"; "http/1.1"] *) 79 + alpn_protocols ~preferred:[ Http_2; Http_1_1 ] 80 + (* Returns: ["h2"; "http/1.1"] *) 81 81 ]} *) 82 82 83 83 (** {1 Version Detection} *)
+5 -5
lib/huri.ml
··· 22 22 values. For all other URI operations, use the [uri] opam library directly. 23 23 24 24 {[ 25 - (* Use Uri for parsing and manipulation *) 26 - let uri = Uri.of_string "https://example.com/path" in 27 - let host = Uri.host uri in 25 + (* Use Uri for parsing and manipulation *) 26 + let uri = Uri.of_string "https://example.com/path" in 27 + let host = Uri.host uri in 28 28 29 - (* Use Huri.write for efficient serialization to Buf_write *) 30 - Eio.Buf_write.with_flow flow (fun w -> Huri.write w uri) 29 + (* Use Huri.write for efficient serialization to Buf_write *) 30 + Eio.Buf_write.with_flow flow (fun w -> Huri.write w uri) 31 31 ]} *) 32 32 33 33 (** {1 Type Alias} *)
+5 -5
lib/huri.mli
··· 23 23 {2 Usage} 24 24 25 25 {[ 26 - (* Use Uri for parsing and manipulation *) 27 - let uri = Uri.of_string "https://example.com/path" in 28 - let host = Uri.host uri in 26 + (* Use Uri for parsing and manipulation *) 27 + let uri = Uri.of_string "https://example.com/path" in 28 + let host = Uri.host uri in 29 29 30 - (* Use Huri.write for efficient serialization to Buf_write *) 31 - Eio.Buf_write.with_flow flow (fun w -> Huri.write w uri) 30 + (* Use Huri.write for efficient serialization to Buf_write *) 31 + Eio.Buf_write.with_flow flow (fun w -> Huri.write w uri) 32 32 ]} *) 33 33 34 34 (** {1 Type Alias} *)
+16 -16
lib/response.mli
··· 150 150 151 151 Example: 152 152 {[ 153 - match Response.cache_control response with 154 - | Some cc when cc.Cache_control.no_store -> "Do not cache" 155 - | Some cc -> Fmt.str "Max age: %d" (Option.get cc.max_age) 156 - | None -> "No cache directives" 153 + match Response.cache_control response with 154 + | Some cc when cc.Cache_control.no_store -> "Do not cache" 155 + | Some cc -> Fmt.str "Max age: %d" (Option.get cc.max_age) 156 + | None -> "No cache directives" 157 157 ]} *) 158 158 159 159 val cache_control_raw : t -> string option ··· 215 215 216 216 Example: 217 217 {[ 218 - let body = Response.body response in 219 - let buffer = Buffer.create 4096 in 220 - Eio.Flow.copy body (Eio.Flow.buffer_sink buffer); 221 - Buffer.contents buffer 218 + let body = Response.body response in 219 + let buffer = Buffer.create 4096 in 220 + Eio.Flow.copy body (Eio.Flow.buffer_sink buffer); 221 + Buffer.contents buffer 222 222 ]} *) 223 223 224 224 val text : t -> string ··· 233 233 234 234 Example: 235 235 {[ 236 - let json = Response.json response in 237 - process_json json 236 + let json = Response.json response in 237 + process_json json 238 238 ]} 239 239 240 240 @raise Eio.Io with {!Error.Json_parse_error} if JSON parsing fails. ··· 274 274 275 275 This is useful for failing fast on HTTP errors: 276 276 {[ 277 - let response = Requests.get req url |> Response.raise_for_status in 278 - (* Only reaches here if status < 400 *) 279 - process_success response 277 + let response = Requests.get req url |> Response.raise_for_status in 278 + (* Only reaches here if status < 400 *) 279 + process_success response 280 280 ]} 281 281 282 282 @raise Eio.Io with [Error.Http_error] if status code >= 400. *) ··· 290 290 291 291 Example: 292 292 {[ 293 - match Response.check_status response with 294 - | Ok resp -> process_success resp 295 - | Error err -> handle_error err 293 + match Response.check_status response with 294 + | Ok resp -> process_success resp 295 + | Error err -> handle_error err 296 296 ]} 297 297 298 298 Per Recommendation #21: Provides a Result-based alternative to