Commits

Anonymous committed 4acde38

Amall_http: POST forms parser

Comments (0)

Files changed (1)

 ;
 
 
+value (request_with_post_vars
+: request -> I.iteratee char (request * list (string * string))
+)
+request
+ =
+  I.gather_to_string >>= fun s ->
+  let vars =
+    s
+    >> String.split_exact ((=) '&')
+    >> List.map
+         (fun binding ->
+            let (var_key, eq_sign, var_val) =
+              String.split_by_first ((=) '=') binding
+            in
+              if eq_sign = ""
+              then
+                (* решение "хоть как-то" *)
+                (var_key, "")
+              else
+                (var_key, String.urldecode var_val)
+         )
+  in
+  let () =
+    List.iter
+      (fun (k, v) ->
+         dbg "body: %s = %S" k v
+      )
+      vars
+  in
+  I.return (request, vars)
+;
+
+
+
 (***************************************************************)