package ez_api
Easy API library and tools
Install
Dune Dependency
github.com
Readme
LGPL-2.1-only WITH OCaml-LGPL-linking-exception License
Edit opam file
Versions (6)
Authors
Maintainers
Sources
v1.0.0.tar.gz
md5=d4dcb8a0be9cf87fca6471cecf083d9a
sha512=452a5de00bf0b51926d9c4c5c9062981c372ebce9ccfd0586b1e1b9b42c96721035dc7cd405e4bdd936ae0a7e69f442e4063713756b7cdac246319198fb89e2c
doc/src/ez_api.server_utils/file.ml.html
Source file file.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
module FileString = struct let size = 16_000 let s = Bytes.make size '\000' let b = Buffer.create size let read_file ic = Buffer.clear b; let rec iter ic b s = let nread = input ic s 0 size in if nread > 0 then begin Buffer.add_subbytes b s 0 nread; iter ic b s end in iter ic b s; Buffer.contents b let read_file filename = let ic = open_in_bin filename in try let s = read_file ic in close_in ic; s with e -> close_in ic; raise e end let normalize_path path = let rec normalize_path path revpath = match path, revpath with | [],_ -> List.rev revpath | ("" | ".") :: path, _ -> normalize_path path revpath | ".." :: path, _ :: revpath -> normalize_path path revpath | ".." :: path, [] -> normalize_path path [] | dir :: path, revpath -> normalize_path path (dir :: revpath) in normalize_path path [] let rec reply ?(meth=`GET) ?default root path = let path = normalize_path path in let file = Filename.concat root (String.concat "/" path) in let content_type = EzAPI.Mime.content_type_of_file file in match meth with | `OPTIONS -> if Sys.file_exists file then Lwt.return {Answer.code = 200; body = ""; headers = ["access-control-allow-methods", "GET"]} else begin match default with | None -> Lwt.return {Answer.code = 404; body = ""; headers = []} | Some file -> reply ~meth root (String.split_on_char '/' file) end | _ -> let body = FileString.read_file file in EzDebug.printf "Returning file %S of length %d" file (String.length body); Lwt.return {Answer.code = 200; body; headers = ["content-type", content_type]}
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>