diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-13 12:08:05 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-13 12:56:28 +0100 |
commit | ab203acf554993d15e37604773f160c84b4d8252 (patch) | |
tree | 45428aa45bc751f788cc5c52c32b15bb8a2363f1 /src/xhr/formdata.nim | |
parent | bf761bcb6dcc5288a86aa5e8c2b67df3f0df056b (diff) | |
download | chawan-ab203acf554993d15e37604773f160c84b4d8252.tar.gz |
Move http out of main binary
Now it is (technically) no longer mandatory to link to libcurl. Also, Chawan is at last completely protocol and network backend agnostic :) * Implement multipart requests in local CGI * Implement simultaneous download of CGI data * Add REQUEST_HEADERS env var with all headers * cssparser: add a missing check in consumeEscape
Diffstat (limited to 'src/xhr/formdata.nim')
-rw-r--r-- | src/xhr/formdata.nim | 15 |
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(): |