From ab203acf554993d15e37604773f160c84b4d8252 Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 13 Dec 2023 12:08:05 +0100 Subject: 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 --- src/xhr/formdata.nim | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/xhr') 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(): -- cgit 1.4.1-2-gfad0