Commits

Anonymous committed 30ac7c4

+ Amall_http.get_cookies

Comments (0)

Files changed (2)

src/amall_http.ml

  = fun str ->
      Urilex.content_type (Lexing.from_string str)
 ;
+
+
+value get_cookies
+ : rq_headers -> list (string * string)
+ = fun h ->
+     loop h.rq_all
+     where rec loop lst =
+       match lst with
+       [ [] -> []
+       | [(hk, hv) :: t] ->
+           if String.eq_nocase_latin1 hk "Cookie"
+           then
+             let lb = Lexing.from_string hv in
+             try
+               Urilex.cookie_string lb
+             with
+             [ _ -> [] ]
+           else
+             loop t
+       ]
+;
 
 let g_char = ['\x00' - '\x7F']
 
+(* cookies *)
+
+let g_cookie_octet =
+  [ '\x21' '\x23'-'\x2B' '\x2D'-'\x3A' '\x3C'-'\x5B' '\x5D'-'\x7E' ]
+
+
+(* rules *)
 
 rule uri = parse
   (scheme as scheme) ":"
     { failwith "expected \\x00..\\x7F after backslash, found %C" c }
 
 
+(* cookies *)
 
+and cookie_string = parse
+  SP* ""
+    { cookie_pair [] lexbuf }
 
+and cookie_pair acc = parse
+  (token as cn) '='
+    { let cv = cookie_value lexbuf in
+      cookie_pair_cont ((cn, cv) :: acc) lexbuf
+    }
 
+and cookie_pair_cont acc = parse
+  SP* eof
+    { List.rev acc }
+| ";" SP
+    { cookie_pair acc lexbuf }
 
+and cookie_name = parse
+  token
+    { Lexing.lexeme lexbuf }
 
+and cookie_value = parse
+  '"' (g_cookie_octet* as v) '"'
+    { v }
+| (g_cookie_octet* as v)
+    { v }
 
 
 
+
+
+
+
+
+
+
+
+
+
+