about summary refs log tree commit diff stats
path: root/src/io/buffer.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-08-08 18:11:42 +0200
committerbptato <nincsnevem662@gmail.com>2022-08-08 18:11:54 +0200
commite2203257e07aada157be9d0a948273cb9d683072 (patch)
tree1b50351e0e9d0f6843a46c48aad3338a067384e8 /src/io/buffer.nim
parente7ea9c408667a4fdfefc369e51d72c3cfb9c1ee9 (diff)
downloadchawan-e2203257e07aada157be9d0a948273cb9d683072.tar.gz
Refactor fileloader
Diffstat (limited to 'src/io/buffer.nim')
-rw-r--r--src/io/buffer.nim15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index c9cb64a0..08feb73f 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -933,8 +933,8 @@ type
     url*: string
     httpmethod*: HttpMethod
     mimetype*: string
-    body*: string
-    multipart*: MimeData
+    body*: Option[string]
+    multipart*: Option[MimeData]
 
 # https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-the-form-data-set
 proc constructEntryList(form: HTMLFormElement, submitter: Element = nil, encoding: string = ""): Table[string, string] =
@@ -1029,7 +1029,6 @@ proc makeCRLF(s: string): string =
     inc i
 
 proc serializeMultipartFormData(kvs: Table[string, string]): MimeData =
-  new(result)
   for name, value in kvs:
     let name = makeCRLF(name)
     let value = makeCRLF(value)
@@ -1080,18 +1079,18 @@ proc submitForm(form: HTMLFormElement, submitter: Element): Option[ClickAction]
     return ClickAction(url: $parsedaction, httpmethod: httpmethod).some
 
   template submitAsEntityBody() =
-    var body: string
     var mimetype: string
-    var multipart: MimeData
+    var body = none(string)
+    var multipart = none(MimeData)
     case enctype
     of FORM_ENCODING_TYPE_URLENCODED:
-      body = serializeApplicationXWWFormUrlEncoded(entrylist)
+      body = serializeApplicationXWWFormUrlEncoded(entrylist).some
       mimeType = $enctype
     of FORM_ENCODING_TYPE_MULTIPART:
-      multipart = serializeMultipartFormData(entrylist) 
+      multipart = serializeMultipartFormData(entrylist).some
       mimetype = $enctype
     of FORM_ENCODING_TYPE_TEXT_PLAIN:
-      body = serializePlainTextFormData(entrylist)
+      body = serializePlainTextFormData(entrylist).some
       mimetype = $enctype
     return ClickAction(url: $parsedaction, httpmethod: httpmethod, body: body, mimetype: mimetype, multipart: multipart).some