elisp如何解析http响应头

web后端返回一些内容给emacs,带有一些参数,以前是直接写在http的body里,今天发现把web后端返回的内容写在http响应头里似乎也是比较常见的做法。于是在服务端自定义了http响应头

header("Content-Type: text/emacs-org");
header("Buffer-name: temp.org");

以前用网上找到的代码(re-search-forward "^$") (delete-region (+ (point) 1) (point-min)) 直接把响应头删了,只要body部分,现在想解析http响应头,不知道elisp有没有什么通用的解析办法没有。

(with-current-buffer (url-retrieve-synchronously "http://example.com")
  (set-buffer-multibyte t)
  (goto-char (point-min))
  (forward-line 1)
  (let (headers body)
    (while (re-search-forward "^\\([^:]*\\): \\(.+\\)"
                              url-http-end-of-headers t)
      (push (cons (match-string 1)
                  (match-string 2))
            headers))
    (setq headers (nreverse headers))
    (goto-char (1+ url-http-end-of-headers))
    (setq body (buffer-substring (point) (point-max)))
    (list headers body)))
;; =>
((("Content-Encoding" . "gzip")
  ("Accept-Ranges" . "bytes")
  ("Age" . "346238")
  ("Cache-Control" . "max-age=604800")
  ("Content-Type" . "text/html; charset=UTF-8")
  ("Date" . "Tue, 21 Sep 2021 08:43:01 GMT")
  ("Etag" . "\"3147526947\"")
  ("Expires" . "Tue, 28 Sep 2021 08:43:01 GMT")
  ("Last-Modified" . "Thu, 17 Oct 2019 07:18:26 GMT")
  ("Server" . "ECS (sab/5784)")
  ("Vary" . "Accept-Encoding")
  ("X-Cache" . "HIT")
  ("Content-Length" . "648"))
 "<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta charset=\"utf-8\" />\n    <meta http-equiv=\"Con\
tent-type\" content=\"text/html; charset=utf-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /\
>\n    <style type=\"text/css\">\n    body {\n        background-color: #f0f0f2;\n        margin: 0;\n        padding: 0;\n       \
 font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, san\
s-serif;\n        \n    }\n    div {\n        width: 600px;\n        margin: 5em auto;\n        padding: 2em;\n        background-\
color: #fdfdff;\n        border-radius: 0.5em;\n        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n    }\n    a:link, a:visite\
d {\n        color: #38488f;\n        text-decoration: none;\n    }\n    @media (max-width: 700px) {\n        div {\n            m\
argin: 0 auto;\n            width: auto;\n        }\n    }\n    </style>    \n</head>\n\n<body>\n<div>\n    <h1>Example Domain</h1\
>\n    <p>This domain is for use in illustrative examples in documents. You may use this\n    domain in literature without prior c\
oordination or asking for permission.</p>\n    <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</\
div>\n</body>\n</html>\n")

text/org; charset=UTF-8? 官方的 mimetype 是 text/org

感谢大佬,确实应该用 Content-Type: text/org,虽然约定成俗这么写,但是应该没有那个浏览器能显示渲染后的org文件,期待那天浏览器能直接支持text/org,这样就不用想尽办法来把org文件转成html了