summaryrefslogtreecommitdiff
path: root/lib/ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-07-21 15:16:57 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-07-21 15:16:57 -0400
commitefeb64a601c052ed533caee0131befe2c96bb91c (patch)
tree4be6d87576e314c5a2a1ecbaed89913bceca422f /lib/ur
parent8ac6c0fe4425753c64fa0ef0a129d33eef36cb5c (diff)
Top.postFields
Diffstat (limited to 'lib/ur')
-rw-r--r--lib/ur/basis.urs6
-rw-r--r--lib/ur/top.ur12
-rw-r--r--lib/ur/top.urs2
3 files changed, 20 insertions, 0 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index 8ac94668..cb5d16ea 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -898,6 +898,12 @@ type postBody
val postType : postBody -> string
val postData : postBody -> string
+type postField
+val firstFormField : string -> option postField
+val fieldName : postField -> string
+val fieldValue : postField -> string
+val remainingFields : postField -> string
+
con radio = [Body, Radio]
val radio : formTag (option string) radio [Id = id]
val radioOption : unit -> tag ([Value = string, Checked = bool] ++ boxAttrs) radio [] [] []
diff --git a/lib/ur/top.ur b/lib/ur/top.ur
index e504204e..5b9d43ab 100644
--- a/lib/ur/top.ur
+++ b/lib/ur/top.ur
@@ -393,3 +393,15 @@ fun mkRead' [t ::: Type] (f : string -> option t) (name : string) : read t =
mkRead (fn s => case f s of
None => error <xml>Invalid {txt name}: {txt s}</xml>
| Some v => v) f
+
+fun postFields pb =
+ let
+ fun postFields' s =
+ case firstFormField s of
+ None => []
+ | Some f => (fieldName f, fieldValue f) :: postFields' (remainingFields f)
+ in
+ case postType pb of
+ "application/x-www-form-urlencoded" => postFields' (postData pb)
+ | _ => error <xml>Tried to get POST fields, but MIME type is not "application/x-www-form-urlencoded"</xml>
+ end
diff --git a/lib/ur/top.urs b/lib/ur/top.urs
index 489e744d..30f1eaad 100644
--- a/lib/ur/top.urs
+++ b/lib/ur/top.urs
@@ -281,3 +281,5 @@ val eqNullable' : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
-> sql_exp tables agg exps bool
val mkRead' : t ::: Type -> (string -> option t) -> string -> read t
+
+val postFields : postBody -> list (string * string)