package dream-accept

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file dream_accept.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
type media_type = Accept.media_type =
  | Media_type of string * string
  | Any_media_subtype of string
  | Any

type charset = Accept.charset = Charset of string | Any

type encoding = Accept.encoding =
  | Encoding of string
  | Gzip
  | Compress
  | Deflate
  | Identity
  | Any

type language = Accept.language = Language of string | Any

let accepted_charsets req =
  Accept.charsets @@ Dream.header req "Accept-Charset"
  |> Accept.qsort |> List.map snd

let accepted_charsets_with_quality req =
  Accept.charsets @@ Dream.header req "Accept-Charset"

let accept_charsets charsets req =
  let charsets = Accept.string_of_charsets charsets in
  Dream.add_header req charsets "Accept-Charset";
  req

let accepted_encodings req =
  Accept.encodings @@ Dream.header req "Accept-Encoding"
  |> Accept.qsort |> List.map snd

let accepted_encodings_with_quality req =
  Accept.encodings @@ Dream.header req "Accept-Encoding"

let accept_encodings encodings req =
  let encodings = Accept.string_of_encodings encodings in
  Dream.add_header req encodings "Accept-Encoding";
  req

let accepted_languages req =
  Accept.languages @@ Dream.header req "Accept-Language"
  |> Accept.qsort |> List.map snd

let accepted_languages_with_quality req =
  Accept.languages @@ Dream.header req "Accept-Language"

let accept_languages languages req =
  let languages = Accept.string_of_languages languages in
  Dream.add_header req languages "Accept-Language";
  req

let accepted_media_types req =
  Accept.media_types @@ Dream.header req "Accept"
  |> Accept.qsort
  |> List.map (fun x -> fst (snd x))

let accepted_media_types_with_quality req =
  Accept.media_types @@ Dream.header req "Accept"
  |> List.map (fun (i, x) -> (i, fst x))

let accept_media_types media_types req =
  let media_types =
    Accept.string_of_media_types
      (List.map (fun (i, x) -> (i, (x, []))) media_types)
  in
  Dream.add_header req media_types "Accept";
  req
OCaml

Innovation. Community. Security.