From 56f4c3e8125ba1d9e3b8f9db4721449b31254a34 Mon Sep 17 00:00:00 2001 From: yifei Date: Sun, 20 Sep 2020 14:45:01 -0400 Subject: [PATCH] Allow file reading in the middle of request body --- restclient.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/restclient.el b/restclient.el index 32d81a8..b9fada2 100644 --- a/restclient.el +++ b/restclient.el @@ -459,10 +459,16 @@ The buffer contains the raw HTTP response sent by the server." (insert-file-contents path) (buffer-string))) +(defun restclient-replace-path-with-contents (entity) + (replace-regexp-in-string + restclient-file-regexp + (lambda (match) + (string-match restclient-file-regexp match) + (restclient-read-file (match-string 1 match))) + entity)) + (defun restclient-parse-body (entity vars) - (if (= 0 (or (string-match restclient-file-regexp entity) 1)) - (restclient-read-file (match-string 1 entity)) - (restclient-replace-all-in-string vars entity))) + (restclient-replace-path-with-contents (restclient-replace-all-in-string vars entity))) (defun restclient-parse-hook (cb-type args-offset args) (if-let ((handler (assoc cb-type restclient-result-handlers)))