1 ;;;; web-request.test --- HTTP requests -*- mode: scheme; coding: utf-8; -*-
3 ;;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free Software
17 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 (define-module (test-suite web-request)
21 #:use-module (web uri)
22 #:use-module (web request)
23 #:use-module (test-suite lib))
26 ;; The newlines are equivalent to \n.
29 Host: localhost:8080\r
30 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Safari/531.2+ Epiphany/2.30.2\r
31 Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r
32 Accept-Encoding: gzip\r
33 Accept-Language: en-gb, en;q=0.9\r
37 (define (requests-equal? r1 r2)
38 (and (equal? (request-method r1) (request-method r2))
39 (equal? (request-uri r1) (request-uri r2))
40 (equal? (request-version r1) (request-version r2))
41 (equal? (request-headers r1) (request-headers r2))))
43 (with-test-prefix "example-1"
45 (pass-if "read-request"
47 (set! r (read-request (open-input-string example-1)))
51 (request-host (build-request (string->uri "http://www.gnu.org/")))
52 '("www.gnu.org" . #f)))
54 (pass-if (equal? (request-method r) 'GET))
56 (pass-if (equal? (request-uri r) (build-uri 'http #:path "/qux")))
58 (pass-if (equal? (read-request-body r) #f))
60 (pass-if "checking all headers"
63 '((host . ("localhost" . 8080))
64 (user-agent . "Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Safari/531.2+ Epiphany/2.30.2")
65 (accept . ((application/xml)
66 (application/xhtml+xml)
68 (text/plain (q . 800))
71 (accept-encoding . ((1000 . "gzip")))
72 (accept-language . ((1000 . "en-gb") (900 . "en"))))))
74 ;; works because there is no body
75 (pass-if "write then read"
76 (requests-equal? (with-input-from-string
77 (with-output-to-string
79 (write-request r (current-output-port))))
81 (read-request (current-input-port))))
84 (pass-if "by accessor"
85 (equal? (request-accept-encoding r) '((1000 . "gzip"))))))