summaryrefslogtreecommitdiff
path: root/neocities
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2023-10-02 13:41:39 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2023-10-02 21:48:41 +0200
commited802e3e8da3440f5a07a49f2b3fb59ba240eeb4 (patch)
tree45bf5bef9caa591c8c1505e99ef84a6ed84e41c9 /neocities
parent809afa9b76fcf9920dacd9bd54655d1517594f1c (diff)
requests: fix multipart/form-data
Diffstat (limited to 'neocities')
-rw-r--r--neocities/requests.scm20
1 files changed, 12 insertions, 8 deletions
diff --git a/neocities/requests.scm b/neocities/requests.scm
index a99e296..d0270c2 100644
--- a/neocities/requests.scm
+++ b/neocities/requests.scm
@@ -67,6 +67,9 @@
#:path (string-append "/api/" endpoint)
#:query (encode-querystring querystring)))
+(define (to-ascii st)
+ (string->bytevector st "ascii"))
+
(define (encode-multipart-body files)
"files is an alist with the filename and destination"
@@ -85,26 +88,27 @@
(define (encode-file file)
(bytevector-append
- (string->utf8
+ (to-ascii
(string-append
"Content-Disposition: form-data;"
- "filename=\"" (destination file) "\"\r\n"
+ " name=\"" (destination file) "\";"
+ " filename=\"" (destination file) "\"\r\n"
"Content-Type: " (type file) " \r\n\r\n"))
- (call-with-input-file (name file) get-bytevector-all #:binary #t)
- (string->utf8 "\r\n")))
+ (call-with-input-file (name file) get-bytevector-all #:binary #t)))
(define boundary
- (string-append "----------------------------------------------------------"
- (random-token)))
+ (string-append "-------------------" (random-token)))
(values boundary
(apply bytevector-append
(map (lambda (file i)
(bytevector-append
- (string->utf8 (string-append boundary "\r\n"))
+ (to-ascii (string-append
+ (if (= i 0) "" "\r\n")
+ "--" boundary "\r\n"))
(encode-file file)
(if (= (+ i 1) (length files))
- (string->utf8 (string-append "\r\n" boundary "--\r\n\r\n"))
+ (to-ascii (string-append "\r\n" "--" boundary "--\r\n"))
#vu8())))
files
(iota (length files))))))