client.scm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. ;;; Web client
  2. ;; Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 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* (tls-wrap port server #:key (verify-certificate? #t))
  156. "Return PORT wrapped in a TLS connection to SERVER. SERVER must be a DNS
  157. host name without trailing dot."
  158. (define (log level str)
  159. (format (current-error-port)
  160. "gnutls: [~a|~a] ~a" (getpid) level str))
  161. (load-gnutls)
  162. (let ((session (make-session connection-end/client))
  163. (ca-certs (x509-certificate-directory)))
  164. ;; Some servers such as 'cloud.github.com' require the client to support
  165. ;; the 'SERVER NAME' extension. However, 'set-session-server-name!' is
  166. ;; not available in older GnuTLS releases. See
  167. ;; <http://bugs.gnu.org/18526> for details.
  168. (if (module-defined? (resolve-interface '(gnutls))
  169. 'set-session-server-name!)
  170. (set-session-server-name! session server-name-type/dns server)
  171. (format (current-error-port)
  172. "warning: TLS 'SERVER NAME' extension not supported~%"))
  173. (set-session-transport-fd! session (fileno port))
  174. (set-session-default-priority! session)
  175. ;; The "%COMPAT" bit allows us to work around firewall issues (info
  176. ;; "(gnutls) Priority Strings"); see <http://bugs.gnu.org/23311>.
  177. ;; Explicitly disable SSLv3, which is insecure:
  178. ;; <https://tools.ietf.org/html/rfc7568>.
  179. (set-session-priorities! session "NORMAL:%COMPAT:-VERS-SSL3.0")
  180. (set-session-credentials! session
  181. (if verify-certificate?
  182. (make-credendials-with-ca-trust-files
  183. ca-certs)
  184. (make-certificate-credentials)))
  185. ;; Uncomment the following lines in case of debugging emergency.
  186. ;;(set-log-level! 10)
  187. ;;(set-log-procedure! log)
  188. (catch 'gnutls-error
  189. (lambda ()
  190. (handshake session))
  191. (lambda (key err proc . rest)
  192. (cond ((eq? err error/warning-alert-received)
  193. ;; Like Wget, do no stop upon non-fatal alerts such as
  194. ;; 'alert-description/unrecognized-name'.
  195. (format (current-error-port)
  196. "warning: TLS warning alert received: ~a~%"
  197. (alert-description->string (alert-get session)))
  198. (handshake session))
  199. (else
  200. ;; XXX: We'd use 'gnutls_error_is_fatal' but (gnutls) doesn't
  201. ;; provide a binding for this.
  202. (apply throw key err proc rest)))))
  203. ;; Verify the server's certificate if needed.
  204. (when verify-certificate?
  205. (catch 'tls-certificate-error
  206. (lambda ()
  207. (assert-valid-server-certificate session server))
  208. (lambda args
  209. (close-port port)
  210. (apply throw args))))
  211. ;; FIXME: It appears that session-record-port is entirely
  212. ;; sufficient; it's already a port. The only value of this code is
  213. ;; to keep a reference on "port", to keep it alive! To fix this we
  214. ;; need to arrange to either hand GnuTLS its own fd to close, or to
  215. ;; arrange a reference from the session-record-port to the
  216. ;; underlying socket.
  217. (let ((record (session-record-port session)))
  218. (define (read! bv start count)
  219. (define read-bv
  220. (catch 'gnutls-error
  221. (lambda ()
  222. (get-bytevector-some record))
  223. (lambda (key err proc . rest)
  224. ;; When responding to "Connection: close" requests, some
  225. ;; servers close the connection abruptly after sending the
  226. ;; response body, without doing a proper TLS connection
  227. ;; termination. Treat it as EOF.
  228. (if (eq? err error/premature-termination)
  229. the-eof-object
  230. (apply throw key err proc rest)))))
  231. (if (eof-object? read-bv)
  232. 0 ; read! returns 0 on eof-object
  233. (let ((read-bv-len (bytevector-length read-bv)))
  234. (bytevector-copy! read-bv 0 bv start (min read-bv-len count))
  235. (when (< count read-bv-len)
  236. (unget-bytevector record bv count (- read-bv-len count)))
  237. read-bv-len)))
  238. (define (write! bv start count)
  239. (put-bytevector record bv start count)
  240. (force-output record)
  241. count)
  242. (define (get-position)
  243. (rnrs-ports:port-position record))
  244. (define (set-position! new-position)
  245. (rnrs-ports:set-port-position! record new-position))
  246. (define (close)
  247. (unless (port-closed? port)
  248. (close-port port))
  249. (unless (port-closed? record)
  250. (close-port record)))
  251. (setvbuf record 'block)
  252. ;; Return a port that wraps RECORD to ensure that closing it also
  253. ;; closes PORT, the actual socket port, and its file descriptor.
  254. ;; XXX: This wrapper would be unnecessary if GnuTLS could
  255. ;; automatically close SESSION's file descriptor when RECORD is
  256. ;; closed, but that doesn't seem to be possible currently (as of
  257. ;; 3.6.9).
  258. (make-custom-binary-input/output-port "gnutls wrapped port" read! write!
  259. get-position set-position!
  260. close))))
  261. (define (ensure-uri-reference uri-or-string)
  262. (cond
  263. ((string? uri-or-string) (string->uri-reference uri-or-string))
  264. ((uri-reference? uri-or-string) uri-or-string)
  265. (else (error "Invalid URI-reference" uri-or-string))))
  266. (define (setup-http-tunnel port uri)
  267. "Establish over PORT an HTTP tunnel to the destination server of URI."
  268. (define target
  269. (string-append (uri-host uri) ":"
  270. (number->string
  271. (or (uri-port uri)
  272. (match (uri-scheme uri)
  273. ('http 80)
  274. ('https 443))))))
  275. (format port "CONNECT ~a HTTP/1.1\r\n" target)
  276. (format port "Host: ~a\r\n\r\n" target)
  277. (force-output port)
  278. (read-response port))
  279. (define* (open-socket-for-uri uri-or-string
  280. #:key (verify-certificate? #t))
  281. "Return an open input/output port for a connection to URI-OR-STRING.
  282. When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates."
  283. (define uri
  284. (ensure-uri-reference uri-or-string))
  285. (define https?
  286. (eq? 'https (uri-scheme uri)))
  287. (define (open-socket)
  288. (define http-proxy
  289. (if https? (current-https-proxy) (current-http-proxy)))
  290. (define uri (ensure-uri-reference (or http-proxy uri-or-string)))
  291. (define addresses
  292. (let ((port (uri-port uri)))
  293. (delete-duplicates
  294. (getaddrinfo (uri-host uri)
  295. (cond (port => number->string)
  296. ((uri-scheme uri) => symbol->string)
  297. (else (error "Not an absolute URI" uri)))
  298. (if port
  299. AI_NUMERICSERV
  300. 0))
  301. (lambda (ai1 ai2)
  302. (equal? (addrinfo:addr ai1) (addrinfo:addr ai2))))))
  303. (let loop ((addresses addresses))
  304. (let* ((ai (car addresses))
  305. (s (with-fluids ((%default-port-encoding #f))
  306. ;; Restrict ourselves to TCP.
  307. (socket (addrinfo:fam ai) SOCK_STREAM IPPROTO_IP))))
  308. (catch 'system-error
  309. (lambda ()
  310. (connect s (addrinfo:addr ai))
  311. ;; Buffer input and output on this port.
  312. (setvbuf s 'block)
  313. ;; If we're using a proxy, make a note of that.
  314. (when http-proxy (set-http-proxy-port?! s #t))
  315. s)
  316. (lambda args
  317. ;; Connection failed, so try one of the other addresses.
  318. (close s)
  319. (if (null? (cdr addresses))
  320. (apply throw args)
  321. (loop (cdr addresses))))))))
  322. (let ((s (open-socket)))
  323. ;; Buffer input and output on this port.
  324. (setvbuf s 'block %http-receive-buffer-size)
  325. (when (and https? (current-https-proxy))
  326. (setup-http-tunnel s uri))
  327. (if https?
  328. (tls-wrap s (uri-host uri)
  329. #:verify-certificate? verify-certificate?)
  330. s)))
  331. (define (extend-request r k v . additional)
  332. (let ((r (set-field r (request-headers)
  333. (assoc-set! (copy-tree (request-headers r))
  334. k v))))
  335. (if (null? additional)
  336. r
  337. (apply extend-request r additional))))
  338. ;; -> request body
  339. (define (sanitize-request request body)
  340. "\"Sanitize\" the given request and body, ensuring that they are
  341. complete and coherent. This method is most useful for methods that send
  342. data to the server, like POST, but can be used for any method. Return
  343. two values: a request and a bytevector, possibly the same ones that were
  344. passed as arguments.
  345. If BODY is a string, encodes the string to a bytevector, in an encoding
  346. appropriate for REQUEST. Adds a ‘content-length’ and ‘content-type’
  347. header, as necessary.
  348. If BODY is a procedure, it is called with a port as an argument, and the
  349. output collected as a bytevector. In the future we might try to instead
  350. use a compressing, chunk-encoded port, and call this procedure later.
  351. Authors are advised not to rely on the procedure being called at any
  352. particular time.
  353. Note that we rely on the request itself already having been validated,
  354. as is the case by default with a request returned by `build-request'."
  355. (cond
  356. ((not body)
  357. (let ((length (request-content-length request)))
  358. (if length
  359. ;; FIXME make this stricter: content-length header should be
  360. ;; prohibited if there's no body, even if the content-length
  361. ;; is 0.
  362. (unless (zero? length)
  363. (error "content-length, but no body"))
  364. (when (assq 'transfer-encoding (request-headers request))
  365. (error "transfer-encoding not allowed with no body")))
  366. (values request #vu8())))
  367. ((string? body)
  368. (let* ((type (request-content-type request '(text/plain)))
  369. (declared-charset (assq-ref (cdr type) 'charset))
  370. (charset (or declared-charset "utf-8")))
  371. (sanitize-request
  372. (if declared-charset
  373. request
  374. (extend-request request 'content-type
  375. `(,@type (charset . ,charset))))
  376. (string->bytevector body charset))))
  377. ((procedure? body)
  378. (let* ((type (request-content-type request
  379. '(text/plain)))
  380. (declared-charset (assq-ref (cdr type) 'charset))
  381. (charset (or declared-charset "utf-8")))
  382. (sanitize-request
  383. (if declared-charset
  384. request
  385. (extend-request request 'content-type
  386. `(,@type (charset . ,charset))))
  387. (call-with-encoded-output-string charset body))))
  388. ((not (bytevector? body))
  389. (error "unexpected body type"))
  390. (else
  391. (values (let ((rlen (request-content-length request))
  392. (blen (bytevector-length body)))
  393. (cond
  394. (rlen (if (= rlen blen)
  395. request
  396. (error "bad content-length" rlen blen)))
  397. (else (extend-request request 'content-length blen))))
  398. body))))
  399. (define (decode-response-body response body)
  400. ;; `body' is either #f or a bytevector.
  401. (cond
  402. ((not body) body)
  403. ((bytevector? body)
  404. (let ((rlen (response-content-length response))
  405. (blen (bytevector-length body)))
  406. (cond
  407. ((and rlen (not (= rlen blen)))
  408. (error "bad content-length" rlen blen))
  409. ((response-content-type response)
  410. => (lambda (type)
  411. (cond
  412. ((text-content-type? (car type))
  413. ;; RFC 2616 3.7.1: "When no explicit charset parameter is
  414. ;; provided by the sender, media subtypes of the "text"
  415. ;; type are defined to have a default charset value of
  416. ;; "ISO-8859-1" when received via HTTP."
  417. (bytevector->string body (or (assq-ref (cdr type) 'charset)
  418. "iso-8859-1")))
  419. (else body))))
  420. (else body))))
  421. (else
  422. (error "unexpected body type" body))))
  423. (define* (http-request uri #:key
  424. (body #f)
  425. (verify-certificate? #t)
  426. (port (open-socket-for-uri uri
  427. #:verify-certificate?
  428. verify-certificate?))
  429. (method 'GET)
  430. (version '(1 . 1))
  431. (keep-alive? #f)
  432. (headers '())
  433. (decode-body? #t)
  434. (streaming? #f)
  435. (request
  436. (build-request
  437. (ensure-uri-reference uri)
  438. #:method method
  439. #:version version
  440. #:headers (if keep-alive?
  441. headers
  442. (cons '(connection close) headers))
  443. #:port port)))
  444. "Connect to the server corresponding to URI and ask for the resource,
  445. using METHOD, defaulting to ‘GET’. If you already have a port open,
  446. pass it as PORT. The port will be closed at the end of the request
  447. unless KEEP-ALIVE? is true. Any extra headers in the alist HEADERS will
  448. be added to the request.
  449. If BODY is not ‘#f’, a message body will also be sent with the HTTP
  450. request. If BODY is a string, it is encoded according to the
  451. content-type in HEADERS, defaulting to UTF-8. Otherwise BODY should be
  452. a bytevector, or ‘#f’ for no body. Although it's allowed to send a
  453. message body along with any request, usually only POST and PUT requests
  454. have bodies. See ‘http-put’ and ‘http-post’ documentation, for more.
  455. If DECODE-BODY? is true, as is the default, the body of the
  456. response will be decoded to string, if it is a textual content-type.
  457. Otherwise it will be returned as a bytevector.
  458. However, if STREAMING? is true, instead of eagerly reading the response
  459. body from the server, this function only reads off the headers. The
  460. response body will be returned as a port on which the data may be read.
  461. Unless KEEP-ALIVE? is true, the port will be closed after the full
  462. response body has been read.
  463. If PORT is false, URI denotes an HTTPS URL, and VERIFY-CERTIFICATE? is
  464. true, verify X.509 certificates against those available in
  465. X509-CERTIFICATE-DIRECTORY.
  466. Returns two values: the response read from the server, and the response
  467. body as a string, bytevector, #f value, or as a port (if STREAMING? is
  468. true)."
  469. (call-with-values (lambda () (sanitize-request request body))
  470. (lambda (request body)
  471. (let ((request (write-request request port)))
  472. (when body
  473. (write-request-body request body))
  474. (force-output (request-port request))
  475. (let ((response (read-response port)))
  476. (cond
  477. ((eq? (request-method request) 'HEAD)
  478. (unless keep-alive?
  479. (close-port port))
  480. (values response #f))
  481. (streaming?
  482. (values response
  483. (response-body-port response
  484. #:keep-alive? keep-alive?
  485. #:decode? decode-body?)))
  486. (else
  487. (let ((body (read-response-body response)))
  488. (unless keep-alive?
  489. (close-port port))
  490. (values response
  491. (if decode-body?
  492. (decode-response-body response body)
  493. body))))))))))
  494. (define-syntax-rule (define-http-verb http-verb method doc)
  495. (define* (http-verb uri #:key
  496. (body #f)
  497. (verify-certificate? #t)
  498. (port (open-socket-for-uri uri
  499. #:verify-certificate?
  500. verify-certificate?))
  501. (version '(1 . 1))
  502. (keep-alive? #f)
  503. (headers '())
  504. (decode-body? #t)
  505. (streaming? #f))
  506. doc
  507. (http-request uri
  508. #:body body #:method method
  509. #:port port #:version version #:keep-alive? keep-alive?
  510. #:headers headers #:decode-body? decode-body?
  511. #:verify-certificate? verify-certificate?
  512. #:streaming? streaming?)))
  513. (define-http-verb http-get
  514. 'GET
  515. "Fetch message headers for the given URI using the HTTP \"GET\"
  516. method.
  517. This function invokes ‘http-request’, with the \"GET\" method. See
  518. ‘http-request’ for full documentation on the various keyword arguments
  519. that are accepted by this function.
  520. Returns two values: the resulting response, and the response body.")
  521. (define-http-verb http-head
  522. 'HEAD
  523. "Fetch message headers for the given URI using the HTTP \"HEAD\"
  524. method.
  525. This function invokes ‘http-request’, with the \"HEAD\" method. See
  526. ‘http-request’ for full documentation on the various keyword arguments
  527. that are accepted by this function.
  528. Returns two values: the resulting response, and ‘#f’. Responses to HEAD
  529. requests do not have a body. The second value is only returned so that
  530. other procedures can treat all of the http-foo verbs identically.")
  531. (define-http-verb http-post
  532. 'POST
  533. "Post data to the given URI using the HTTP \"POST\" method.
  534. This function invokes ‘http-request’, with the \"POST\" method. See
  535. ‘http-request’ for full documentation on the various keyword arguments
  536. that are accepted by this function.
  537. Returns two values: the resulting response, and the response body.")
  538. (define-http-verb http-put
  539. 'PUT
  540. "Put data at the given URI using the HTTP \"PUT\" method.
  541. This function invokes ‘http-request’, with the \"PUT\" 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-delete
  546. 'DELETE
  547. "Delete data at the given URI using the HTTP \"DELETE\" method.
  548. This function invokes ‘http-request’, with the \"DELETE\" 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-trace
  553. 'TRACE
  554. "Send an HTTP \"TRACE\" request.
  555. This function invokes ‘http-request’, with the \"TRACE\" 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-options
  560. 'OPTIONS
  561. "Query characteristics of an HTTP resource using the HTTP \"OPTIONS\"
  562. method.
  563. This function invokes ‘http-request’, with the \"OPTIONS\" method. See
  564. ‘http-request’ for full documentation on the various keyword arguments
  565. that are accepted by this function.
  566. Returns two values: the resulting response, and the response body.")