client.scm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. ;;; Web client
  2. ;; Copyright (C) 2011-2018, 2020-2022 Free Software Foundation, Inc.
  3. ;; This library is free software; you can redistribute it and/or
  4. ;; modify it under the terms of the GNU Lesser General Public
  5. ;; License as published by the Free Software Foundation; either
  6. ;; version 3 of the License, or (at your option) any later version.
  7. ;;
  8. ;; This library is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. ;; Lesser General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU Lesser General Public
  14. ;; License along with this library; if not, write to the Free Software
  15. ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. ;; 02110-1301 USA
  17. ;;; Commentary:
  18. ;;;
  19. ;;; (web client) is a simple HTTP URL fetcher for Guile.
  20. ;;;
  21. ;;; In its current incarnation, (web client) is synchronous. If you
  22. ;;; want to fetch a number of URLs at once, probably the best thing to
  23. ;;; do is to write an event-driven URL fetcher, similar in structure to
  24. ;;; the web server.
  25. ;;;
  26. ;;; Another option, good but not as performant, would be to use threads,
  27. ;;; possibly via a thread pool.
  28. ;;;
  29. ;;; Code:
  30. (define-module (web client)
  31. #:use-module (rnrs bytevectors)
  32. #:use-module (ice-9 binary-ports)
  33. #:use-module (ice-9 copy-tree)
  34. #:use-module (ice-9 iconv)
  35. #:use-module (ice-9 rdelim)
  36. #:use-module (web request)
  37. #:use-module (web response)
  38. #:use-module (web uri)
  39. #:use-module (web http)
  40. #:use-module (srfi srfi-1)
  41. #:use-module (srfi srfi-9)
  42. #:use-module (srfi srfi-9 gnu)
  43. #:use-module (srfi srfi-26)
  44. #:use-module ((rnrs io ports)
  45. #:prefix rnrs-ports:)
  46. #:use-module (ice-9 match)
  47. #:autoload (ice-9 ftw) (scandir)
  48. #:export (current-http-proxy
  49. current-https-proxy
  50. x509-certificate-directory
  51. open-socket-for-uri
  52. http-request
  53. http-get
  54. http-head
  55. http-post
  56. http-put
  57. http-delete
  58. http-trace
  59. http-options))
  60. (define %http-receive-buffer-size
  61. ;; Size of the HTTP receive buffer.
  62. 65536)
  63. ;; Autoload GnuTLS so that this module can be used even when GnuTLS is
  64. ;; not available. At compile time, this yields "possibly unbound
  65. ;; variable" warnings, but these are OK: they'll be resolved at run time
  66. ;; thanks to 'load-gnutls'.
  67. (define (load-gnutls)
  68. "Attempt to load the (gnutls) module. Throw to 'gnutls-not-available
  69. if it is unavailable."
  70. (catch 'misc-error
  71. (lambda ()
  72. ;; XXX: Use this hack instead of #:autoload to avoid compilation
  73. ;; errors. See <http://bugs.gnu.org/12202>.
  74. (module-use! (resolve-module '(web client))
  75. (resolve-interface '(gnutls))))
  76. (lambda _
  77. (throw 'gnutls-not-available "(gnutls) module not available")))
  78. (set! load-gnutls (const #t)))
  79. (define current-http-proxy
  80. (make-parameter (let ((proxy (getenv "http_proxy")))
  81. (and (not (equal? proxy ""))
  82. proxy))))
  83. (define current-https-proxy
  84. (make-parameter (let ((proxy (getenv "https_proxy")))
  85. (and (not (equal? proxy ""))
  86. proxy))))
  87. (define x509-certificate-directory
  88. ;; The directory where X.509 authority PEM certificates are stored.
  89. (make-parameter (or (getenv "GUILE_TLS_CERTIFICATE_DIRECTORY")
  90. (getenv "SSL_CERT_DIR") ;like OpenSSL
  91. "/etc/ssl/certs")))
  92. (define (set-certificate-credentials-x509-trust-file!* cred file format)
  93. "Like 'set-certificate-credentials-x509-trust-file!', but without the file
  94. name decoding bug described at
  95. <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26948#17>."
  96. (let ((data (call-with-input-file file get-bytevector-all)))
  97. (set-certificate-credentials-x509-trust-data! cred data format)))
  98. (define (make-credendials-with-ca-trust-files directory)
  99. "Return certificate credentials with X.509 authority certificates read from
  100. DIRECTORY. Those authority certificates are checked when
  101. 'peer-certificate-status' is later called."
  102. (let ((cred (make-certificate-credentials))
  103. (files (match (scandir directory (cut string-suffix? ".pem" <>))
  104. ((or #f ())
  105. ;; Some distros provide nothing but bundles (*.crt) under
  106. ;; /etc/ssl/certs, so look for them.
  107. (or (scandir directory (cut string-suffix? ".crt" <>))
  108. '()))
  109. (pem pem))))
  110. (for-each (lambda (file)
  111. (let ((file (string-append directory "/" file)))
  112. ;; Protect against dangling symlinks.
  113. (when (file-exists? file)
  114. (set-certificate-credentials-x509-trust-file!*
  115. cred file
  116. x509-certificate-format/pem))))
  117. files)
  118. cred))
  119. (define (peer-certificate session)
  120. "Return the certificate of the remote peer in SESSION."
  121. (match (session-peer-certificate-chain session)
  122. ((first _ ...)
  123. (import-x509-certificate first x509-certificate-format/der))))
  124. (define (assert-valid-server-certificate session server)
  125. "Return #t if the certificate of the remote peer for SESSION is a valid
  126. certificate for SERVER, where SERVER is the expected host name of peer."
  127. (define cert
  128. (peer-certificate session))
  129. ;; First check whether the server's certificate matches SERVER.
  130. (unless (x509-certificate-matches-hostname? cert server)
  131. (throw 'tls-certificate-error 'host-mismatch cert server))
  132. ;; Second check its validity and reachability from the set of authority
  133. ;; certificates loaded via 'set-certificate-credentials-x509-trust-file!'.
  134. (match (peer-certificate-status session)
  135. (() ;certificate is valid
  136. #t)
  137. ((statuses ...)
  138. (throw 'tls-certificate-error 'invalid-certificate cert server
  139. statuses))))
  140. (define (print-tls-certificate-error port key args default-printer)
  141. "Print the TLS certificate error represented by ARGS in an intelligible
  142. way."
  143. (match args
  144. (('host-mismatch cert server)
  145. (format port
  146. "X.509 server certificate for '~a' does not match: ~a~%"
  147. server (x509-certificate-dn cert)))
  148. (('invalid-certificate cert server statuses)
  149. (format port
  150. "X.509 certificate of '~a' could not be verified:~% ~a~%"
  151. server
  152. (string-join (map certificate-status->string statuses))))))
  153. (set-exception-printer! 'tls-certificate-error
  154. print-tls-certificate-error)
  155. (define (wrap-record-port-for-gnutls<3.7.7 record port)
  156. "Return a port that wraps RECORD to ensure that closing it also closes PORT,
  157. the actual socket port, and its file descriptor. Make sure it does not
  158. introduce extra buffering (custom ports are buffered by default as of Guile
  159. 3.0.5).
  160. This wrapper is unnecessary with GnuTLS >= 3.7.7, which can automatically
  161. close SESSION's file descriptor when RECORD is closed."
  162. (define (read! bv start count)
  163. (define read
  164. (catch 'gnutls-error
  165. (lambda ()
  166. (get-bytevector-n! record bv start count))
  167. (lambda (key err proc . rest)
  168. ;; When responding to "Connection: close" requests, some servers
  169. ;; close the connection abruptly after sending the response body,
  170. ;; without doing a proper TLS connection termination. Treat it as
  171. ;; EOF. This is fixed in GnuTLS 3.7.7.
  172. (if (eq? err error/premature-termination)
  173. the-eof-object
  174. (apply throw key err proc rest)))))
  175. (if (eof-object? read)
  176. 0
  177. read))
  178. (define (write! bv start count)
  179. (put-bytevector record bv start count)
  180. (force-output record)
  181. count)
  182. (define (get-position)
  183. (port-position record))
  184. (define (set-position! new-position)
  185. (set-port-position! record new-position))
  186. (define (close)
  187. (unless (port-closed? port)
  188. (close-port port))
  189. (unless (port-closed? record)
  190. (close-port record)))
  191. (define (unbuffered port)
  192. (setvbuf port 'none)
  193. port)
  194. (unbuffered
  195. (make-custom-binary-input/output-port "gnutls wrapped port" read! write!
  196. get-position set-position!
  197. close)))
  198. (define* (tls-wrap port server #:key (verify-certificate? #t))
  199. "Return PORT wrapped in a TLS connection to SERVER. SERVER must be a DNS
  200. host name without trailing dot."
  201. (define (log level str)
  202. (format (current-error-port)
  203. "gnutls: [~a|~a] ~a" (getpid) level str))
  204. (load-gnutls)
  205. (let ((session (make-session connection-end/client))
  206. (ca-certs (x509-certificate-directory)))
  207. ;; Some servers such as 'cloud.github.com' require the client to support
  208. ;; the 'SERVER NAME' extension. However, 'set-session-server-name!' is
  209. ;; not available in older GnuTLS releases. See
  210. ;; <http://bugs.gnu.org/18526> for details.
  211. (if (module-defined? (resolve-interface '(gnutls))
  212. 'set-session-server-name!)
  213. (set-session-server-name! session server-name-type/dns server)
  214. (format (current-error-port)
  215. "warning: TLS 'SERVER NAME' extension not supported~%"))
  216. (set-session-transport-fd! session (fileno port))
  217. (set-session-default-priority! session)
  218. ;; The "%COMPAT" bit allows us to work around firewall issues (info
  219. ;; "(gnutls) Priority Strings"); see <http://bugs.gnu.org/23311>.
  220. ;; Explicitly disable SSLv3, which is insecure:
  221. ;; <https://tools.ietf.org/html/rfc7568>.
  222. (set-session-priorities! session "NORMAL:%COMPAT:-VERS-SSL3.0")
  223. (set-session-credentials! session
  224. (if verify-certificate?
  225. (make-credendials-with-ca-trust-files
  226. ca-certs)
  227. (make-certificate-credentials)))
  228. ;; Uncomment the following lines in case of debugging emergency.
  229. ;;(set-log-level! 10)
  230. ;;(set-log-procedure! log)
  231. (let loop ((retries 5))
  232. (catch 'gnutls-error
  233. (lambda ()
  234. (handshake session))
  235. (lambda (key err proc . rest)
  236. (cond ((eq? err error/warning-alert-received)
  237. ;; Like Wget, do no stop upon non-fatal alerts such as
  238. ;; 'alert-description/unrecognized-name'.
  239. (format (current-error-port)
  240. "warning: TLS warning alert received: ~a~%"
  241. (alert-description->string (alert-get session)))
  242. (handshake session))
  243. (else
  244. (if (or (fatal-error? err) (zero? retries))
  245. (apply throw key err proc rest)
  246. (begin
  247. ;; We got 'error/again' or similar; try again.
  248. (format (current-error-port)
  249. "warning: TLS non-fatal error: ~a~%"
  250. (error->string err))
  251. (loop (- retries 1)))))))))
  252. ;; Verify the server's certificate if needed.
  253. (when verify-certificate?
  254. (catch 'tls-certificate-error
  255. (lambda ()
  256. (assert-valid-server-certificate session server))
  257. (lambda args
  258. (close-port port)
  259. (apply throw args))))
  260. (let ((record (session-record-port session)))
  261. (setvbuf record 'block)
  262. (if (module-defined? (resolve-interface '(gnutls))
  263. 'set-session-record-port-close!) ;GnuTLS >= 3.7.7
  264. (let ((close-wrapped-port (lambda (_) (close-port port))))
  265. (set-session-record-port-close! record close-wrapped-port)
  266. record)
  267. (wrap-record-port-for-gnutls<3.7.7 record port)))))
  268. (define (ensure-uri-reference uri-or-string)
  269. (cond
  270. ((string? uri-or-string) (string->uri-reference uri-or-string))
  271. ((uri-reference? uri-or-string) uri-or-string)
  272. (else (error "Invalid URI-reference" uri-or-string))))
  273. (define (setup-http-tunnel port uri)
  274. "Establish over PORT an HTTP tunnel to the destination server of URI."
  275. (define target
  276. (string-append (uri-host uri) ":"
  277. (number->string
  278. (or (uri-port uri)
  279. (match (uri-scheme uri)
  280. ('http 80)
  281. ('https 443))))))
  282. (format port "CONNECT ~a HTTP/1.1\r\n" target)
  283. (format port "Host: ~a\r\n\r\n" target)
  284. (force-output port)
  285. (read-response port))
  286. (define* (open-socket-for-uri uri-or-string
  287. #:key (verify-certificate? #t))
  288. "Return an open input/output port for a connection to URI-OR-STRING.
  289. When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates."
  290. (define uri
  291. (ensure-uri-reference uri-or-string))
  292. (define https?
  293. (eq? 'https (uri-scheme uri)))
  294. (define (open-socket)
  295. (define http-proxy
  296. (if https? (current-https-proxy) (current-http-proxy)))
  297. (define uri (ensure-uri-reference (or http-proxy uri-or-string)))
  298. (define addresses
  299. (let ((port (uri-port uri)))
  300. (delete-duplicates
  301. (getaddrinfo (uri-host uri)
  302. (cond (port => number->string)
  303. ((uri-scheme uri) => symbol->string)
  304. (else (error "Not an absolute URI" uri)))
  305. (if port
  306. AI_NUMERICSERV
  307. 0))
  308. (lambda (ai1 ai2)
  309. (equal? (addrinfo:addr ai1) (addrinfo:addr ai2))))))
  310. (let loop ((addresses addresses))
  311. (let* ((ai (car addresses))
  312. (s (with-fluids ((%default-port-encoding #f))
  313. ;; Restrict ourselves to TCP.
  314. (socket (addrinfo:fam ai) SOCK_STREAM IPPROTO_IP))))
  315. (catch 'system-error
  316. (lambda ()
  317. (connect s (addrinfo:addr ai))
  318. ;; Buffer input and output on this port.
  319. (setvbuf s 'block)
  320. ;; If we're using a proxy, make a note of that.
  321. (when http-proxy (set-http-proxy-port?! s #t))
  322. s)
  323. (lambda args
  324. ;; Connection failed, so try one of the other addresses.
  325. (close s)
  326. (if (null? (cdr addresses))
  327. (apply throw args)
  328. (loop (cdr addresses))))))))
  329. (let ((s (open-socket)))
  330. ;; Buffer input and output on this port.
  331. (setvbuf s 'block %http-receive-buffer-size)
  332. (when (and https? (current-https-proxy))
  333. (setup-http-tunnel s uri))
  334. (if https?
  335. (tls-wrap s (uri-host uri)
  336. #:verify-certificate? verify-certificate?)
  337. s)))
  338. (define (extend-request r k v . additional)
  339. (let ((r (set-field r (request-headers)
  340. (assoc-set! (copy-tree (request-headers r))
  341. k v))))
  342. (if (null? additional)
  343. r
  344. (apply extend-request r additional))))
  345. ;; -> request body
  346. (define (sanitize-request request body)
  347. "\"Sanitize\" the given request and body, ensuring that they are
  348. complete and coherent. This method is most useful for methods that send
  349. data to the server, like POST, but can be used for any method. Return
  350. two values: a request and a bytevector, possibly the same ones that were
  351. passed as arguments.
  352. If BODY is a string, encodes the string to a bytevector, in an encoding
  353. appropriate for REQUEST. Adds a ‘content-length’ and ‘content-type’
  354. header, as necessary.
  355. If BODY is a procedure, it is called with a port as an argument, and the
  356. output collected as a bytevector. In the future we might try to instead
  357. use a compressing, chunk-encoded port, and call this procedure later.
  358. Authors are advised not to rely on the procedure being called at any
  359. particular time.
  360. Note that we rely on the request itself already having been validated,
  361. as is the case by default with a request returned by `build-request'."
  362. (cond
  363. ((not body)
  364. (let ((length (request-content-length request)))
  365. (if length
  366. ;; FIXME make this stricter: content-length header should be
  367. ;; prohibited if there's no body, even if the content-length
  368. ;; is 0.
  369. (unless (zero? length)
  370. (error "content-length, but no body"))
  371. (when (assq 'transfer-encoding (request-headers request))
  372. (error "transfer-encoding not allowed with no body")))
  373. (values request #vu8())))
  374. ((string? body)
  375. (let* ((type (request-content-type request '(text/plain)))
  376. (declared-charset (assq-ref (cdr type) 'charset))
  377. (charset (or declared-charset "utf-8")))
  378. (sanitize-request
  379. (if declared-charset
  380. request
  381. (extend-request request 'content-type
  382. `(,@type (charset . ,charset))))
  383. (string->bytevector body charset))))
  384. ((procedure? body)
  385. (let* ((type (request-content-type request
  386. '(text/plain)))
  387. (declared-charset (assq-ref (cdr type) 'charset))
  388. (charset (or declared-charset "utf-8")))
  389. (sanitize-request
  390. (if declared-charset
  391. request
  392. (extend-request request 'content-type
  393. `(,@type (charset . ,charset))))
  394. (call-with-encoded-output-string charset body))))
  395. ((not (bytevector? body))
  396. (error "unexpected body type"))
  397. (else
  398. (values (let ((rlen (request-content-length request))
  399. (blen (bytevector-length body)))
  400. (cond
  401. (rlen (if (= rlen blen)
  402. request
  403. (error "bad content-length" rlen blen)))
  404. (else (extend-request request 'content-length blen))))
  405. body))))
  406. (define (decode-response-body response body)
  407. ;; `body' is either #f or a bytevector.
  408. (cond
  409. ((not body) body)
  410. ((bytevector? body)
  411. (let ((rlen (response-content-length response))
  412. (blen (bytevector-length body)))
  413. (cond
  414. ((and rlen (not (= rlen blen)))
  415. (error "bad content-length" rlen blen))
  416. ((response-content-type response)
  417. => (lambda (type)
  418. (cond
  419. ((text-content-type? (car type))
  420. ;; RFC 2616 3.7.1: "When no explicit charset parameter is
  421. ;; provided by the sender, media subtypes of the "text"
  422. ;; type are defined to have a default charset value of
  423. ;; "ISO-8859-1" when received via HTTP."
  424. (bytevector->string body (or (assq-ref (cdr type) 'charset)
  425. "iso-8859-1")))
  426. (else body))))
  427. (else body))))
  428. (else
  429. (error "unexpected body type" body))))
  430. (define* (http-request uri #:key
  431. (body #f)
  432. (verify-certificate? #t)
  433. (port (open-socket-for-uri uri
  434. #:verify-certificate?
  435. verify-certificate?))
  436. (method 'GET)
  437. (version '(1 . 1))
  438. (keep-alive? #f)
  439. (headers '())
  440. (decode-body? #t)
  441. (streaming? #f)
  442. (request
  443. (build-request
  444. (ensure-uri-reference uri)
  445. #:method method
  446. #:version version
  447. #:headers (if keep-alive?
  448. headers
  449. (cons '(connection close) headers))
  450. #:port port)))
  451. "Connect to the server corresponding to URI and ask for the resource,
  452. using METHOD, defaulting to ‘GET’. If you already have a port open,
  453. pass it as PORT. The port will be closed at the end of the request
  454. unless KEEP-ALIVE? is true. Any extra headers in the alist HEADERS will
  455. be added to the request.
  456. If BODY is not ‘#f’, a message body will also be sent with the HTTP
  457. request. If BODY is a string, it is encoded according to the
  458. content-type in HEADERS, defaulting to UTF-8. Otherwise BODY should be
  459. a bytevector, or ‘#f’ for no body. Although it's allowed to send a
  460. message body along with any request, usually only POST and PUT requests
  461. have bodies. See ‘http-put’ and ‘http-post’ documentation, for more.
  462. If DECODE-BODY? is true, as is the default, the body of the
  463. response will be decoded to string, if it is a textual content-type.
  464. Otherwise it will be returned as a bytevector.
  465. However, if STREAMING? is true, instead of eagerly reading the response
  466. body from the server, this function only reads off the headers. The
  467. response body will be returned as a port on which the data may be read.
  468. Unless KEEP-ALIVE? is true, the port will be closed after the full
  469. response body has been read.
  470. If PORT is false, URI denotes an HTTPS URL, and VERIFY-CERTIFICATE? is
  471. true, verify X.509 certificates against those available in
  472. X509-CERTIFICATE-DIRECTORY.
  473. Returns two values: the response read from the server, and the response
  474. body as a string, bytevector, #f value, or as a port (if STREAMING? is
  475. true)."
  476. (call-with-values (lambda () (sanitize-request request body))
  477. (lambda (request body)
  478. (let ((request (write-request request port)))
  479. (when body
  480. (write-request-body request body))
  481. (force-output (request-port request))
  482. (let ((response (read-response port)))
  483. (cond
  484. ((eq? (request-method request) 'HEAD)
  485. (unless keep-alive?
  486. (close-port port))
  487. (values response #f))
  488. (streaming?
  489. (values response
  490. (response-body-port response
  491. #:keep-alive? keep-alive?
  492. #:decode? decode-body?)))
  493. (else
  494. (let ((body (read-response-body response)))
  495. (unless keep-alive?
  496. (close-port port))
  497. (values response
  498. (if decode-body?
  499. (decode-response-body response body)
  500. body))))))))))
  501. (define-syntax-rule (define-http-verb http-verb method doc)
  502. (define* (http-verb uri #:key
  503. (body #f)
  504. (verify-certificate? #t)
  505. (port (open-socket-for-uri uri
  506. #:verify-certificate?
  507. verify-certificate?))
  508. (version '(1 . 1))
  509. (keep-alive? #f)
  510. (headers '())
  511. (decode-body? #t)
  512. (streaming? #f))
  513. doc
  514. (http-request uri
  515. #:body body #:method method
  516. #:port port #:version version #:keep-alive? keep-alive?
  517. #:headers headers #:decode-body? decode-body?
  518. #:verify-certificate? verify-certificate?
  519. #:streaming? streaming?)))
  520. (define-http-verb http-get
  521. 'GET
  522. "Fetch message headers for the given URI using the HTTP \"GET\"
  523. method.
  524. This function invokes ‘http-request’, with the \"GET\" method. See
  525. ‘http-request’ for full documentation on the various keyword arguments
  526. that are accepted by this function.
  527. Returns two values: the resulting response, and the response body.")
  528. (define-http-verb http-head
  529. 'HEAD
  530. "Fetch message headers for the given URI using the HTTP \"HEAD\"
  531. method.
  532. This function invokes ‘http-request’, with the \"HEAD\" method. See
  533. ‘http-request’ for full documentation on the various keyword arguments
  534. that are accepted by this function.
  535. Returns two values: the resulting response, and ‘#f’. Responses to HEAD
  536. requests do not have a body. The second value is only returned so that
  537. other procedures can treat all of the http-foo verbs identically.")
  538. (define-http-verb http-post
  539. 'POST
  540. "Post data to the given URI using the HTTP \"POST\" method.
  541. This function invokes ‘http-request’, with the \"POST\" method. See
  542. ‘http-request’ for full documentation on the various keyword arguments
  543. that are accepted by this function.
  544. Returns two values: the resulting response, and the response body.")
  545. (define-http-verb http-put
  546. 'PUT
  547. "Put data at the given URI using the HTTP \"PUT\" method.
  548. This function invokes ‘http-request’, with the \"PUT\" method. See
  549. ‘http-request’ for full documentation on the various keyword arguments
  550. that are accepted by this function.
  551. Returns two values: the resulting response, and the response body.")
  552. (define-http-verb http-delete
  553. 'DELETE
  554. "Delete data at the given URI using the HTTP \"DELETE\" method.
  555. This function invokes ‘http-request’, with the \"DELETE\" method. See
  556. ‘http-request’ for full documentation on the various keyword arguments
  557. that are accepted by this function.
  558. Returns two values: the resulting response, and the response body.")
  559. (define-http-verb http-trace
  560. 'TRACE
  561. "Send an HTTP \"TRACE\" request.
  562. This function invokes ‘http-request’, with the \"TRACE\" method. See
  563. ‘http-request’ for full documentation on the various keyword arguments
  564. that are accepted by this function.
  565. Returns two values: the resulting response, and the response body.")
  566. (define-http-verb http-options
  567. 'OPTIONS
  568. "Query characteristics of an HTTP resource using the HTTP \"OPTIONS\"
  569. method.
  570. This function invokes ‘http-request’, with the \"OPTIONS\" method. See
  571. ‘http-request’ for full documentation on the various keyword arguments
  572. that are accepted by this function.
  573. Returns two values: the resulting response, and the response body.")