-
Notifications
You must be signed in to change notification settings - Fork 3
/
mb-url.el
184 lines (163 loc) · 5.96 KB
/
mb-url.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
;;; mb-url.el --- Multiple Backends for Emacs URL package -*- lexical-binding: t; -*-
;; Copyright (C) 2015, 2016, 2018, 2019, 2021-2023 ZHANG Weiyi
;; Author: ZHANG Weiyi <dochang@gmail.com>
;; Version: 0.12.0
;; Package-Requires: ((emacs "25"))
;; Keywords: comm, data, processes, hypermedia
;; URL: https://github.com/dochang/mb-url
;; This file is not part of GNU Emacs.
;;; License:
;; This program is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the Free
;; Software Foundation, either version 3 of the License, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
;; more details.
;; You should have received a copy of the GNU General Public License along with
;; this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; <!-- markdown-link-check-disable -->
;; [![MELPA](http://melpa.org/packages/mb-url-badge.svg)](http://melpa.org/#/mb-url)
;; [![MELPA Stable](http://stable.melpa.org/packages/mb-url-badge.svg)](http://stable.melpa.org/#/mb-url)
;; [![CI](https://github.com/dochang/mb-url/actions/workflows/ci.yml/badge.svg)](https://github.com/dochang/mb-url/actions/workflows/ci.yml)
;; [![CircleCI](https://dl.circleci.com/status-badge/img/gh/dochang/mb-url/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/dochang/mb-url/tree/master)
;; [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/dochang/mb-url.svg)](http://isitmaintained.com/project/dochang/mb-url "Average time to resolve an issue")
;; [![Percentage of issues still open](http://isitmaintained.com/badge/open/dochang/mb-url.svg)](http://isitmaintained.com/project/dochang/mb-url "Percentage of issues still open")
;; [![Issues](https://img.shields.io/github/issues/dochang/mb-url.svg)](https://github.com/dochang/mb-url)
;; [![Pull Requests](https://img.shields.io/github/issues-pr/dochang/mb-url.svg)](https://github.com/dochang/mb-url)
;; [![GitHub](https://img.shields.io/github/license/dochang/mb-url)](https://github.com/dochang/mb-url/blob/master/LICENSE)
;; [![Say Thanks!](https://img.shields.io/badge/say-thanks-green)](https://saythanks.io/to/dochang)
;; <!--
;; See the following issues for details.
;;
;; <https://github.com/BlitzKraft/saythanks.io/issues/60>
;; <https://github.com/BlitzKraft/saythanks.io/issues/103>
;; -->
;; <!-- markdown-link-check-enable -->
;;
;; Multiple Backends for URL package.
;;
;; This package provides several backends for `url-retrieve' &
;; `url-retrieve-synchronously', which replace the internal implementation.
;;
;; The motivation of this package is I can't connect HTTPS url behind proxy
;; (Related bugs: [#11788][], [#12636][], [#18860][], [msg00756][], [#10][]).
;;
;; [#11788]: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11788
;; [#12636]: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12636
;; [#18860]: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18860
;; [msg00756]: https://lists.gnu.org/archive/html/help-gnu-emacs/2015-08/msg00756.html
;; [#10]: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10
;; Notice:
;;
;; As the URL package has supported HTTPS over proxies supporting CONNECT since
;; Emacs 26, this package is no longer recommended. But it can still be used
;; in Emacs < 26.
;; Installation:
;;
;; `mb-url' is available on [MELPA] and [el-get].
;;
;; [MELPA]: https://melpa.org/
;; [el-get]: https://github.com/dimitri/el-get
;;
;; To install `mb-url' from git repository, clone the repo, then add the repo
;; dir into `load-path'.
;;
;; `mb-url' depends on `cl-lib'; The test code also depends on `s'.
;; Backends:
;;
;; Currently only support `url-http'.
;;
;; `url-http`:
;;
;; Install `mb-url-http-around-advice' to use `mb-url-http' backends.
;;
;; ```elisp
;; (advice-add 'url-http :around 'mb-url-http-around-advice)
;; ```
;;
;; All backend functions receive `(name url buffer default-sentinel)', return a
;; process.
;;
;; `mb-url-http-backend' indicates the current backend. If the backend is
;; `nil', which means no backend, `url-http' will be called.
;;
;; E.g.,
;;
;; ```elisp
;; (setq mb-url-http-backend 'mb-url-http-curl)
;; ```
;;
;; NOTE: All clients are required to support automatically decompressing
;; response bodies.
;;
;; #### [cURL][]
;;
;; [cURL]: http://curl.haxx.se/
;;
;; ##### `mb-url-http-curl'
;;
;; cURL backend for `url-http'.
;;
;; ##### `mb-url-http-curl-program'
;;
;; cURL program.
;;
;; ##### `mb-url-http-curl-switches'
;;
;; cURL switches.
;;
;; #### [HTTPie][]
;;
;; [HTTPie]: http://httpie.org/
;;
;; ##### `mb-url-http-httpie'
;;
;; HTTPie backend for `url-http'.
;;
;; ##### `mb-url-http-httpie-program'
;;
;; HTTPie program.
;;
;; ##### `mb-url-http-httpie-switches'
;;
;; HTTPie switches.
;;
;; ##### `mb-url-http-httpie-supported-content-encoding-list'
;;
;; Content encodings which HTTPie supports to decode.
;;
;; If your HTTPie supports to decode a encoding like `br`, put the encoding
;; into this list.
;;
;; By default, HTTPie supports to decode `gzip` and `deflate`.
;;
;; ##### `mb-url-http-httpie-content-encoding-fix-function'
;;
;; A function to fix the value of `Content-Encoding` for HTTPie. Default
;; value is `mb-url-http-httpie-delete-content-encoding-from-list'.
;; License:
;;
;; GPLv3
;; Acknowledgements:
;;
;; <https://github.com/nicferrier/curl-url-retrieve>
;;; Code:
(require 'cl-lib)
(defgroup mb-url ()
"Multiple Backends for URL package."
:prefix "mb-url-"
:group 'url)
(defmacro mb-url-with-gensyms (symbols &rest body)
"Bind SYMBOLS to unique temporary symbols then execute BODY in the context."
(declare (indent 1))
`(let ,(mapcar (lambda (sym) `(,sym (cl-gensym))) symbols)
,@body))
(defun mb-url-string-empty-p (string)
"Check whether STRING is nil or empty."
(or (null string)
(string= string "")))
(provide 'mb-url)
;;; mb-url.el ends here