url.el 怎么界定 HTTP Headers 和 Body?

比如:

(display-buffer (url-retrieve-synchronously "http://example.com"))

接收的信息:

HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Mon, 27 May 2019 14:37:04 GMT
Etag: "1541025663"
Expires: Mon, 03 Jun 2019 14:37:04 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (oxr/830F)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 606

<!doctype html>
<html>
...
</html>

现在需要解析 Body(即上面的 HTML 文档),原来我一直用 url-http-end-of-headers

(with-current-buffer (url-retrieve-synchronously "http://example.com")
  (display-buffer (current-buffer))
  (goto-char url-http-end-of-headers))

现在突然发现当 Cache 开着的时候,url-http-end-of-headers 就不管用了,参见 Bug#35927。目测 (re-search-forward "^$") 能解决这个问题,好奇大家是怎么解决的?对这 "^$" 不是很确定。

\r\n\r\n

1 个赞

(re-search-forward "\r\n\r\n") 搜索失败,(re-search-forward "\n\n") 可以,可能 Emacs 渲染的时候把 \r 去掉了?