package vif
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
A simple web framework for OCaml 5
Install
dune-project
Dependency
Authors
Maintainers
Sources
vif-0.0.1.beta5.tbz
sha256=f2dafa4f12105d85b4dc2d1e1492f03e809c85d5834dc5694b99226418fe2719
sha512=1e2087db43e8e13bfc240c1114790ceb702b941d389bbb94a7a18668e65f61d2224f05038cf9101ede890581b0e2227e4d2bd2c620f312fa18c8e37482e273c4
doc/src/vif.core/vif_request.ml.html
Source file vif_request.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113let src = Logs.Src.create "vif.request" module Log = (val Logs.src_log src : Logs.LOG) let error_msgf fmt = Fmt.kstr (fun msg -> Error (`Msg msg)) fmt type ('socket, 'c, 'a) t = { body: [ `V1 of H1.Body.Reader.t | `V2 of H2.Body.Reader.t ] ; encoding: ('c, 'a) Vif_type.t ; env: Vif_middleware.Hmap.t ; request: 'socket Vif_request0.t } let of_req0 : type c a. encoding:(c, a) Vif_type.t -> env:Vif_middleware.Hmap.t -> 'socket Vif_request0.t -> ('socket, c, a) t = fun ~encoding ~env request -> let body = Vif_request0.request_body request in { request; body; encoding; env } let target { request; _ } = Vif_request0.target request let meth { request; _ } = Vif_request0.meth request let version { request; _ } = Vif_request0.version request let headers { request; _ } = Vif_request0.headers request let reqd { request; _ } = Vif_request0.reqd request let source { request; _ } = Vif_request0.source request let accept { request; _ } = Vif_request0.accept request let close { request; _ } = Vif_request0.close request let shutdown { request; _ } = Vif_request0.shutdown request let { request; _ } = Vif_request0.tags request let to_string { request; _ } = let src = Vif_request0.source request in Flux.Stream.from src |> Flux.Stream.into Flux.Sink.string let to_reader (Flux.Source { init; pull; _ }) = let src = ref (init ()) in let rec fn () = match pull !src with | Some ("", src') -> src := src'; (fn [@tailcall]) () | Some (str, src') -> src := src'; let first = 0 and length = String.length str in Bytesrw.Bytes.Slice.make (Bytes.of_string str) ~first ~length | None -> Bytesrw.Bytes.Slice.eod in Bytesrw.Bytes.Reader.make fn let is_empty req = let hdrs = headers req in let content_length = Vif_headers.get hdrs "Content-Length" |> Option.map String.trim |> Option.map String.lowercase_ascii in let transfer_encoding = Vif_headers.get hdrs "Transfer-Encoding" |> Option.map String.trim |> Option.map String.lowercase_ascii in match (content_length, transfer_encoding) with | Some "0", _ -> true | Some _, _ | None, Some _ -> false | None, None -> true let of_json : type a. ('socket, Vif_type.json, a) t -> (a, [> `Msg of string ]) result = function | { encoding= Type Any; _ } as req -> Ok (to_string req) | { encoding= Type (Option Any); _ } as req -> if is_empty req then Ok None else Ok (Some (to_string req)) | { encoding= Type (Json_encoding encoding); _ } as req -> begin let from = source req in let reader = to_reader from in match Jsont_bytesrw.decode encoding reader with | exception exn -> Bytesrw.Bytes.Reader.discard reader; error_msgf "Unexpected exception when decoding JSON: %s" (Printexc.to_string exn) | Error msg -> Bytesrw.Bytes.Reader.discard reader; Error (`Msg msg) | Ok _ as value -> value end | { encoding= Type (Option (Json_encoding _)); _ } as req when is_empty req -> Ok None | { encoding= Type (Option (Json_encoding encoding)); _ } as req -> begin let from = source req in let reader = to_reader from in match Jsont_bytesrw.decode encoding reader with | exception exn -> Bytesrw.Bytes.Reader.discard reader; error_msgf "Unexpected exception when decoding JSON: %s" (Printexc.to_string exn) | Error msg -> Bytesrw.Bytes.Reader.discard reader; Error (`Msg msg) | Ok value -> Ok (Some value) end let get : type v. ('socket, 'cfg, v) Vif_middleware.t -> ('socket, 'a, 'c) t -> v option = fun (Vif_middleware.Middleware (_, key)) { env; _ } -> Vif_middleware.Hmap.find key env type 'socket request = 'socket Vif_request0.t let headers_of_request = Vif_request0.headers let method_of_request = Vif_request0.meth let target_of_request = Vif_request0.target
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>