diff --git a/src/headers_lib.ml b/src/headers_lib.ml index 079c176d..289e8018 100644 --- a/src/headers_lib.ml +++ b/src/headers_lib.ml @@ -1,11 +1,11 @@ -(* independent module for headers fields value *) +(* independent library for headers fields value *) (* TODO - test - can still bypass this module and directly set Etag header, but its fine *) module Etag : sig - (* module to parse < "*" / #entity-tag >, - used for If-Match and If-None-Match headers + (* module to parse etags header fields + used by If-Match and If-None-Match headers https://httpwg.org/specs/rfc9110.html#field.etag *) type t diff --git a/src/mte.ml b/src/mte.ml index 79ecd9c5..cd406e4d 100644 --- a/src/mte.ml +++ b/src/mte.ml @@ -13,7 +13,9 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . *) -(* TODO *) +(* TODO ??: GANA error codes + https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *) + (* https://docs.taler.net/core/api-common.html#tsref-type-ErrorDetail *) let error_detail ?hint status = let _ = (hint, status) in @@ -23,6 +25,11 @@ module Respond_with = struct open Vif.Response open Syntax + let bad_request ?hint req = + let body = error_detail ?hint `Bad_request in + let* () = with_string ?compression:None req body in + respond `Bad_request + let not_modified () = let* () = empty in respond `Not_modified @@ -48,21 +55,19 @@ end include a "Avail-Languages" header: a comma-separated list of the languages available *) module Static = struct let f kind req _server _env = - let get_ok = function - | Error e -> Fmt.failwith "TODO handle me, %s" e - | Ok v -> v - in let etag = Assets.etag kind in let headers = Vif.Request.headers req in let has_matching_etag = match Vif.Headers.get headers "if-none-match" with - | None -> false + | None -> Ok false | Some s -> - Headers_lib.Etag.parse s |> get_ok |> Headers_lib.Etag.evaluate etag + Headers_lib.Etag.parse s + |> Result.map (Headers_lib.Etag.evaluate etag) in match has_matching_etag with - | true -> Respond_with.not_modified () - | false -> ( + | Error e -> Respond_with.bad_request ~hint:e req + | Ok true -> Respond_with.not_modified () + | Ok false -> ( match Headers.select_mimetype headers with | None -> Respond_with.unsupported_media_type req | Some mime ->