From f1de641828b34141678f2e11a9820f4dba69b0e0 Mon Sep 17 00:00:00 2001 From: Eitaro Fukamachi Date: Mon, 9 Sep 2019 01:15:06 +0900 Subject: [PATCH] Support for the latest fast-http, which doesn't convert Content-Length into an integer. --- src/backend/usocket.lisp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/backend/usocket.lisp b/src/backend/usocket.lisp index c3496b3..5061728 100644 --- a/src/backend/usocket.lisp +++ b/src/backend/usocket.lisp @@ -180,7 +180,10 @@ ((not has-body) (setq body +empty-body+)) ((and content-length (not transfer-encoding-p)) - (let ((buf (make-array content-length :element-type '(unsigned-byte 8)))) + (let ((buf (make-array (etypecase content-length + (integer content-length) + (string (parse-integer content-length))) + :element-type '(unsigned-byte 8)))) (read-sequence buf stream) (setq body buf))) ((let ((status (http-status http))) @@ -695,8 +698,13 @@ (multiple-value-bind (http body response-headers-data transfer-encoding-p) (with-retrying (read-response stream (not (eq method :head)) verbose (not want-stream))) - (let ((status (http-status http)) - (response-headers (http-headers http))) + (let* ((status (http-status http)) + (response-headers (http-headers http)) + (content-length (gethash "content-length" response-headers)) + (content-length (etypecase content-length + (null content-length) + (string (parse-integer content-length)) + (integer content-length)))) (when (= status 0) (unless reusing-stream-p ;; There's nothing we can do. @@ -730,13 +738,12 @@ ;; Need to read the response body (when (and want-stream (not (eq method :head))) - (let ((content-length (gethash "content-length" response-headers))) - (cond - ((integerp content-length) - (dotimes (i content-length) - (loop until (read-byte body nil nil)))) - (transfer-encoding-p - (read-until-crlf*2 body))))) + (cond + ((integerp content-length) + (dotimes (i content-length) + (loop until (read-byte body nil nil)))) + (transfer-encoding-p + (read-until-crlf*2 body)))) (let ((location-uri (quri:uri (gethash "location" response-headers)))) (if (and (or (null (uri-host location-uri)) @@ -782,7 +789,7 @@ (let ((body (convert-body body (gethash "content-encoding" response-headers) (gethash "content-type" response-headers) - (gethash "content-length" response-headers) + content-length transfer-encoding-p force-binary (connection-keep-alive-p