summaryrefslogtreecommitdiff
path: root/http-client.scm
diff options
context:
space:
mode:
authorPeter Bex <peter@more-magic.net>2022-03-15 08:08:46 +0100
committerPeter Bex <peter@more-magic.net>2022-03-15 08:08:46 +0100
commita4c631332faaf7506f8cc9443c22deb7db2b4335 (patch)
tree5579b9163a5e14e206d5560b63ea22c7ba701d9e /http-client.scm
parentcd301f3a86e15de48d122b112c1f16fa5b316e3f (diff)
downloadhttp-client-a4c631332faaf7506f8cc9443c22deb7db2b4335.tar.gz
Try to determine multipart content length for string ports
This makes it slightly more reliable for certain servers which absolutely require content length. An alternative would be to have an explicit API for sending static string contents. This could be in addition to this approach, because this should always be a net win.
Diffstat (limited to 'http-client.scm')
-rw-r--r--http-client.scm22
1 files changed, 17 insertions, 5 deletions
diff --git a/http-client.scm b/http-client.scm
index 1eef99d..e9c181b 100644
--- a/http-client.scm
+++ b/http-client.scm
@@ -756,6 +756,14 @@
entry))
entries))
+(define (maybe-string-port-length port)
+ (and (eq? (##sys#slot port 7) 'string) ; type
+ (let ((size (##sys#slot port 11))
+ (string (##sys#slot port 12)))
+ (assert (integer? size)) ; Check our assumptions; this is pretty unsafe code
+ (assert (string? string))
+ size)))
+
(define (calculate-chunk-size entries)
(call/cc
(lambda (return)
@@ -763,12 +771,16 @@
(fold (lambda (chunk total-size)
(if (pair? chunk)
(if (eq? 'port (car chunk))
+ (let ((str-len (maybe-string-port-length (cdr chunk))))
+ (if str-len
+ (+ total-size str-len)
+ ;; We can't calculate port lengths
+ ;; for non-string-ports. Let's just
+ ;; punt and hope the server won't
+ ;; return "411 Length Required"...
+ ;; (TODO: maybe try seeking it?)
+ (return #f)))
;; Should be a file otherwise.
- ;; We can't calculate port lengths.
- ;; Let's just punt and hope the server
- ;; won't return "411 Length Required"...
- ;; (TODO: maybe try seeking it?)
- (return #f)
(+ total-size (file-size (cdr chunk))))
(+ total-size (string-length chunk))))
total-size