aboutsummaryrefslogtreecommitdiff
path: root/tests/http-client.scm
blob: 649fa1bfacb90bf3be1ad1120b784b816f9939a4 (about) (plain)
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
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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.
;;;
;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-http-client)
  #:use-module (guix http-client)
  #:use-module (guix tests http)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-64)
  #:use-module (rnrs bytevectors)
  #:use-module (rnrs io ports)
  #:use-module (web response)
  #:use-module (web uri))

(test-begin "http-client")

(test-equal "http-fetch, one request, binary"
  (string->utf8 "Hello, world.")
  (with-http-server `((200 "Hello, world."))
    (let* ((port (http-fetch (%local-url)))
           (bv   (get-bytevector-all port)))
      (close-port port)
      bv)))

(test-equal "http-fetch, one request, text"
  "Hello, world."
  (with-http-server `((200 "Hello, world."))
    (let* ((port (http-fetch (%local-url) #:text? #t))
           (data (get-string-all port)))
      (close-port port)
      data)))

(test-equal "http-fetch, redirect"
  "Hello, world."
  (with-http-server `((,(build-response
                         #:code 301
                         #:headers
                         `((location
                            . ,(string->uri-reference "/elsewhere")))
                         #:reason-phrase "Moved")
                       "Redirect!")
                      (200 "Hello, world."))
    (let* ((port (http-fetch (%local-url)))
           (data (get-string-all port)))
      (close-port port)
      data)))

(test-equal "http-fetch, error"
  404
  (with-http-server `((404 "Ne trovita."))
    (guard (c ((http-get-error? c) (http-get-error-code c)))
      (http-fetch (%local-url))
      #f)))

(test-equal "http-fetch, redirect + error"
  403
  (with-http-server `((,(build-response
                         #:code 302
                         #:headers
                         `((location
                            . ,(string->uri-reference "/elsewhere")))
                         #:reason-phrase "Moved")
                       "Redirect!")
                      (403 "Verboten."))
    (guard (c ((http-get-error? c) (http-get-error-code c)))
      (http-fetch (%local-url))
      #f)))

(test-end "http-client")
:18 +0200'>2021-04-28.guix-authorizations: Remove lle_bout....* .guix-authorizations: Remove lle_bout from the committers. Marius Bakke 2021-04-11.guix-authorizations: Add raghavgururajan....* .guix-authorizations: Add raghavgururajan to the committers. Tobias Geerinckx-Rice 2021-04-09Revert ".guix-authorizations: Remove biscuolo due to inactivity."...The original commit was made mistakenly; I forgot to look at all of our Git repos, including maintenance.git, when checking for recent activity. This reverts commit 94521669ed23096f930be68efc691ccb793cc76f. Leo Famulari 2021-04-07.guix-authorizations: Remove biscuolo due to inactivity....* .guix-authorizations: Remove biscuolo. Leo Famulari 2021-04-07.guix-authorizations: Remove wingo due to inactivity....* .guix-authorizations: Remove wingo. Leo Famulari 2021-04-07.guix-authorizations: Remove sleep_walker due to inactivity....* .guix-authorizations: Remove sleep_walker. Leo Famulari 2021-04-07.guix-authorizations: Remove rhelling due to inactivity....* .guix-authorizations: Remove rhelling. Leo Famulari 2021-04-07.guix-authorizations: Remove lsl88 due to inactivity....* .guix-authorizations: Remove lsl88. Leo Famulari 2021-04-07.guix-authorizations: Remove benwoodcroft due to inactivity....* .guix-authorizations: Remove benwoodcroft. Leo Famulari 2021-04-07.guix-authorizations: Remove alexvong1995 due to inactivity....* .guix-authorizations: Remove alexvong1995. Leo Famulari 2021-04-06.guix-authorizations: Remove taylanub....This is a followup to the events discussed here: https://lists.gnu.org/archive/html/guix-devel/2021-03/msg00195.html Taylan was already removed from the Guix project on Savannah on March 10, 2021. * .guix-authorizations: Remove taylanub from the committers. Leo Famulari 2021-04-06.guix-authorizations: Remove thomasd....* .guix-authorizations: Remove thomasd from the committers. Leo Famulari 2021-03-08.guix-authorizations: Add lbraun....* .guix-authorizations: Add lbraun and "lbraun (professional)" to the committers. Leo Famulari 2021-02-18.guix-authorizations: Add lle_bout....* .guix-authorizations: Add lle_bout to the committers. Tobias Geerinckx-Rice 2020-12-28.guix-authorizations: Add leoprikler....* .guix-authorizations: Add leoprikler to the committers. Ludovic Courtès 2020-11-15.guix-authorizations: Add jonsger....* .guix-authorizations: Add jonsger to the committers. Marius Bakke 2020-10-16.guix-authorizations: Add m1gu3l....* .guix-authorizations: Add m1gu3l to the committers. Ludovic Courtès 2020-09-04.guix-authorizations: Add planglois to the committers....* .guix-authorizations: Add planglois. Ludovic Courtès 2020-07-18.guix-authorizations: Add brettgilio (back) to the committers....* .guix-authorizations: Add fingerprint for brettgilio. Tobias Geerinckx-Rice 2020-07-01.guix-authorizations: Remove keys of two former contributors....* .guix-authorizations: Remove key of David Craven, who left the project in 2017, and Federico Beffa, whose last commit was in Feb. 2017. Ludovic Courtès 2020-07-01.guix-authorizations: Remove former keys that are no longer used....* .guix-authorizations: Remove old keys of dvc, efraim, and janneke. Ludovic Courtès 2020-07-01.guix-authorizations: Remove brettgilio's old key....* .guix-authorizations: Remove key "DFC0 C7F7 9EE6 0CA7 AE55 5E19 6722 43C4 A03F 0EEE" (Brett Gilio). See <https://lists.gnu.org/archive/html/guix-devel/2020-06/msg00323.html>. Ludovic Courtès 2020-05-04.guix-authorizations: Add bricewge to the committers....* .guix-authorizations: Add fingerprint for bricewge. Ludovic Courtès 2020-05-04.guix-authorizations: Augment....* .guix-authorizations: Add all the currently authorized committers. Ludovic Courtès 2020-05-04Add '.guix-authorizations'....* .guix-authorizations: New file. Ludovic Courtès