[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/plz 8d2654bba7 49/81: Add/Change: Handle LF-only HTTP r
From: |
ELPA Syncer |
Subject: |
[elpa] externals/plz 8d2654bba7 49/81: Add/Change: Handle LF-only HTTP responses |
Date: |
Wed, 11 May 2022 17:58:01 -0400 (EDT) |
branch: externals/plz
commit 8d2654bba7bfa11525aef50f969c489c20ac0a43
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add/Change: Handle LF-only HTTP responses
Seems that some Cloudflare responses from the matrix.org server are
using only LF characters between the headers and body (while RFC 2616
requires CRLF). So, rather than fail completely or return invalid
data, we try to accommodate either CRLF or LF-only, but in the latter
case we display a warning (hoping that it will help to understand this
issue and can eventually be removed).
---
plz.el | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/plz.el b/plz.el
index 097e43d420..8e22d037ff 100644
--- a/plz.el
+++ b/plz.el
@@ -559,7 +559,9 @@ according to the apparent coding system."
(save-excursion
(goto-char (point-min))
;; Parse HTTP version and status code.
- (looking-at plz-http-response-status-line-regexp)
+ (unless (looking-at plz-http-response-status-line-regexp)
+ (error "Unable to parse HTTP response status line: %S"
+ (substring-no-properties (buffer-string))))
(let* ((http-version (string-to-number (match-string 1)))
(status-code (string-to-number (match-string 2)))
(headers (plz--headers))
@@ -584,10 +586,14 @@ refer to rather than the current buffer's unparsed
headers."
(defun plz--http-status ()
"Return HTTP status code for HTTP response in current buffer."
+ ;; This function is used in the sentinel to get the HTTP response
+ ;; code without parsing the whole response.
(save-excursion
(goto-char (point-min))
- (when (looking-at plz-http-response-status-line-regexp)
- (string-to-number (match-string 2)))))
+ (unless (looking-at plz-http-response-status-line-regexp)
+ (error "Unable to parse HTTP response status line: %S"
+ (substring-no-properties (buffer-string))))
+ (string-to-number (match-string 2))))
(defun plz--headers ()
"Return headers alist for HTTP response in current buffer."
@@ -595,7 +601,7 @@ refer to rather than the current buffer's unparsed headers."
(goto-char (point-min))
(forward-line 1)
(let ((limit (save-excursion
- (re-search-forward "^\r\n" nil)
+ (plz--skip-headers)
(point))))
(cl-loop while (re-search-forward (rx bol (group (1+ (not (in ":"))))
":" (1+ blank)
(group (1+ (not (in "\r\n")))))
@@ -607,10 +613,30 @@ refer to rather than the current buffer's unparsed
headers."
;; use `alist-get' without having to add "nil nil #'equal"
every time.
collect (cons (intern (downcase (match-string 1)))
(match-string 2))))))
+(defun plz--skip-headers ()
+ "Move point past headers in current HTTP response buffer.
+It seems that some misbehaving HTTP servers use only LF line
+endings rather than the RFC 2616-mandated CRLF endings, so we
+must try to handle either."
+ ;; It seems that this is happening with some Cloudflare responses. :(
+ ;; NOTE: For debugging purposes, I'm inserting these warnings for now. If
this is a solvable
+ ;; bug, or if I come to understand the issue better, they could be removed
or disabled.
+ (condition-case _err
+ (re-search-forward "^\r\n" nil)
+ (search-failed ;; Try LF-only.
+ (condition-case _err
+ (progn
+ (re-search-forward "^\n" nil)
+ (display-warning 'plz (format "Only LF used after headers in HTTP
response: %S"
+ (substring-no-properties
(buffer-string)))))
+ (search-failed
+ (signal 'search-failed (format "Can't find end-of-headers in HTTP
response: %S"
+ (substring-no-properties
(buffer-string)))))))))
+
(defun plz--narrow-to-body ()
"Narrow to body of HTTP response in current buffer."
(goto-char (point-min))
- (re-search-forward "^\r\n" nil)
+ (plz--skip-headers)
(narrow-to-region (point) (point-max)))
;;;; Footer
- [elpa] externals/plz 30e48b1e6a 22/81: Tidy, (continued)
- [elpa] externals/plz 30e48b1e6a 22/81: Tidy, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 05f93b0b6b 25/81: Meta: Update Makefile, makem.sh, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 19a0110109 33/81: Notes: Add ToC, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 9a1b119eff 38/81: Meta: Ignore sandbox/, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 0301272d8d 40/81: Add: plz-put, ELPA Syncer, 2022/05/11
- [elpa] externals/plz a5f22b23e1 42/81: Add: (plz), ELPA Syncer, 2022/05/11
- [elpa] externals/plz 430ceffd1d 43/81: Change: Handle killed processes, ELPA Syncer, 2022/05/11
- [elpa] externals/plz f40d3ecbdd 47/81: Add/Change: :noquery argument for make-process, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 1884d038ae 46/81: Notes: Add note about Lars Ingebrigtsen's with-url macro, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 7478d43668 51/81: Revert "Add/Change: Handle LF-only HTTP responses", ELPA Syncer, 2022/05/11
- [elpa] externals/plz 8d2654bba7 49/81: Add/Change: Handle LF-only HTTP responses,
ELPA Syncer <=
- [elpa] externals/plz 220f882ee4 53/81: Tests: (plz-post-jpeg-string) Add, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 4a246e24f6 54/81: Add: Upload binary files, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 7c27e4bdcd 61/81: Change: Sync with accept-process-output, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 65030d5cc1 64/81: Tidy: Docstring, ELPA Syncer, 2022/05/11
- [elpa] externals/plz dd92f48895 65/81: Change: Default to :then 'sync and :as 'string, ELPA Syncer, 2022/05/11
- [elpa] externals/plz cddccccf81 67/81: Docs: Fix link, ELPA Syncer, 2022/05/11
- [elpa] externals/plz f1a89a8816 68/81: Add: Download :as file, ELPA Syncer, 2022/05/11
- [elpa] externals/plz 8cd1ef481d 73/81: Notes: Add links to skeeto's feedback, ELPA Syncer, 2022/05/11
- [elpa] externals/plz dd491941ab 79/81: Meta: Update makem.sh, ELPA Syncer, 2022/05/11
- [elpa] externals/plz da503527d2 76/81: Change: (plz--response) Error if unable to parse HTTP response, ELPA Syncer, 2022/05/11