This commit is contained in:
Swrup 2025-09-27 18:49:16 +02:00
parent 5342a1281f
commit 1cb610988f
4 changed files with 39 additions and 33 deletions

View file

@ -57,34 +57,31 @@ module Static = struct
(* - try to find a response with an acceptable mime-type,
- then pick the version in the most preferred language of the user,
- and finally apply compression if that is allowed by the client
- set ETAG header
TODO:
- set an ETAG,
- subsequent requests of the client should provide the tag in an "If-None-Match" header
to detect if the terms of service have changed.
- If not, a "304 Not Modified" response will be returned.
Note that the 304 Not Modified will also be returned if the client changed
the "Accept-Language" or "Accept-Encoding" header.
- The ETAG is encoded in Crockford base-32.
- A "Taler-Terms-Version" header is generated to indicate the legal version of the terms.
to detect if the terms of service have changed
- If it did not change, a "304 Not Modified" response will be returned
- The ETAG is encoded in Crockford base-32
- A "Taler-Terms-Version" header is generated to indicate the legal version of the terms
- When returning a full response (not a 304 Not Modified), the server
should also include a Avail-Languages header which includes a
comma-separated list of the languages in which the terms of service are available in
*)
(* accept_ext_l and accept_lang_l are assumed to be sorted by preference *)
let select_file headers kind =
let open Syntax in
let accept_ext_l = Header_util.parse_accept_header headers in
let accept_lang_l = Header_util.parse_accept_language_header headers in
let* ext =
accept_ext_l
headers
|> Header_util.parse_accept_header
|> List.find_opt Assets.is_supported_ext
|> Option.to_result ~none:"no acceptable mimetype"
in
let* lang =
accept_lang_l
headers
|> Header_util.parse_accept_language_header
|> List.find_opt Assets.is_supported_lang
|> Option.to_result ~none:"no acceptable language"
in
@ -96,6 +93,7 @@ module Static = struct
let static kind req _server _env =
let open Vif.Response.Syntax in
let headers = Vif.Request.headers req in
let _if_none_match = Vif.Headers.get headers "if-none-match" in
let data =
match select_file headers kind with
| Error e -> Fmt.failwith "%s" e
@ -103,8 +101,9 @@ module Static = struct
in
let compression = Header_util.select_encoding headers in
let* () = Vif.Response.with_string ?compression req data in
let field = "content-type" in
let* () = Vif.Response.add ~field "html; charset=utf-8" in
let* () = Vif.Response.add ~field:"ETAG" (Assets.etag kind) in
(* TODO content-type *)
let* () = Vif.Response.add ~field:"content-type" "html; charset=utf-8" in
Vif.Response.respond `OK
let terms = static Assets.Terms