about summary refs log tree commit diff stats
path: root/src/xhr/formdata.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/xhr/formdata.nim')
-rw-r--r--src/xhr/formdata.nim15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/xhr/formdata.nim b/src/xhr/formdata.nim
index 84c13402..98c96b54 100644
--- a/src/xhr/formdata.nim
+++ b/src/xhr/formdata.nim
@@ -1,3 +1,6 @@
+import std/base64
+import std/streams
+
 import html/dom
 import html/enums
 import js/domexception
@@ -12,12 +15,20 @@ import chame/tags
 proc constructEntryList*(form: HTMLFormElement, submitter: Element = nil,
     encoding: string = ""): Option[seq[FormDataEntry]]
 
+
+proc generateBoundary(): string =
+  let urandom = newFileStream("/dev/urandom")
+  let s = urandom.readStr(32)
+  urandom.close()
+  # 32 * 4 / 3 (padded) = 44 + prefix string is 22 bytes = 66 bytes
+  return "----WebKitFormBoundary" & base64.encode(s)
+
 proc newFormData0*(): FormData =
-  return FormData()
+  return FormData(boundary: generateBoundary())
 
 proc newFormData*(form: HTMLFormElement = nil,
     submitter: HTMLElement = nil): DOMResult[FormData] {.jsctor.} =
-  let this = FormData()
+  let this = newFormData0()
   if form != nil:
     if submitter != nil:
       if not submitter.isSubmitButton():