emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/plz 1bb701f1c1 36/81: Change/Fix: Downcase and intern h


From: ELPA Syncer
Subject: [elpa] externals/plz 1bb701f1c1 36/81: Change/Fix: Downcase and intern header keys
Date: Wed, 11 May 2022 17:58:00 -0400 (EDT)

branch: externals/plz
commit 1bb701f1c104314ec12e05f1c3ca0b9310b75c35
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Change/Fix: Downcase and intern header keys
    
    Some HTTP servers send all-lowercase header keys, which means an alist
    lookup with `equal' or `string=' fails when the case differs.  We
    don't want users to have to worry about this, so for consistency, we
    downcase the header name.  And while we're at it, we might as well
    intern it so we can use `alist-get' without having to add "nil nil
    'equal" every time.
---
 plz.el            | 7 ++++++-
 tests/test-plz.el | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/plz.el b/plz.el
index 23560bc4c8..fb9a4c742a 100644
--- a/plz.el
+++ b/plz.el
@@ -475,7 +475,12 @@ refer to rather than the current buffer's unparsed 
headers."
       (cl-loop while (re-search-forward (rx bol (group (1+ (not (in ":")))) 
":" (1+ blank)
                                             (group (1+ (not (in "\r\n")))))
                                         limit t)
-               collect (cons (match-string 1) (match-string 2))))))
+               ;; NOTE: Some HTTP servers send all-lowercase header keys, 
which means an alist
+               ;; lookup with `equal' or `string=' fails when the case 
differs.  We don't want
+               ;; users to have to worry about this, so for consistency, we 
downcase the
+               ;; header name.  And while we're at it, we might as well intern 
it so we can
+               ;; use `alist-get' without having to add "nil nil #'equal" 
every time.
+               collect (cons (intern (downcase (match-string 1))) 
(match-string 2))))))
 
 (defun plz--narrow-to-body ()
   "Narrow to body of HTTP response in current buffer."
diff --git a/tests/test-plz.el b/tests/test-plz.el
index 17070866e7..96adc12808 100644
--- a/tests/test-plz.el
+++ b/tests/test-plz.el
@@ -56,7 +56,7 @@
   `(and (should (plz-response-p ,response))
         (should (numberp (plz-response-version ,response)))
         (should (eq 200 (plz-response-status ,response)))
-        (should (equal "application/json" (alist-get "Content-Type" 
(plz-response-headers ,response) nil nil #'equal)))
+        (should (equal "application/json" (alist-get 'content-type 
(plz-response-headers ,response))))
         (let* ((json (json-read-from-string (plz-response-body ,response)))
                (headers (alist-get 'headers json))
                (user-agent (alist-get 'User-Agent headers nil nil #'equal)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]