+ bad_request
This commit is contained in:
parent
0549bb098a
commit
c3e81293af
2 changed files with 17 additions and 12 deletions
23
src/mte.ml
23
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 <https://www.gnu.org/licenses/>. *)
|
||||
|
||||
(* 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 ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue