;;; x400 --- test ‘(www server-utils filesystem) fully-specified’

;; Copyright (C) 2017 Thien-Thi Nguyen
;;
;; This file is part of Guile-WWW.
;;
;; Guile-WWW 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, or
;; (at your option) any later version.
;;
;; Guile-WWW 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 Guile-WWW.  If not, see <http://www.gnu.org/licenses/>.

(use-modules
 (www server-utils filesystem))

(define (chk want got)
  (cond ((equal? want got))
        (else (and verbose? (fse "want: ~S~% got: ~S~%" want got))
              (exit #f))))

(chk #t (fluid? default-text-charset))

(chk '(type "image/jpeg")
     (fully-specified 'type "image/jpeg"))

(chk '(Content-Type "image/jpeg")
     (fully-specified 'Content-Type "image/jpeg"))

(chk "ISO-8859-1" (fluid-ref default-text-charset))

(define raw (filename->content-type (srcdir/ "x400") "text/plain"))
(vfso "raw: ~S~%" raw)
(chk "text/plain" raw)

(define full-type (fully-specified 'type raw))
(vfso "full-type: ~S~%" full-type)
(chk '(type "text/plain" charset "ISO-8859-1")
     full-type)

(define full-Content-Type (fully-specified 'Content-Type raw))
(vfso "full-Content-Type: ~S~%" full-Content-Type)
(chk '(Content-Type "text/plain;charset=ISO-8859-1")
     full-Content-Type)

(fluid-set! default-text-charset "UTF-8")

(chk '(type "image/jpeg")
     (fully-specified 'type "image/jpeg"))

(chk '(Content-Type "image/jpeg")
     (fully-specified 'Content-Type "image/jpeg"))

(chk "UTF-8" (fluid-ref default-text-charset))

(set! full-type (fully-specified 'type raw))
(vfso "full-type: ~S~%" full-type)
(chk '(type "text/plain" charset "UTF-8")
     full-type)

(set! full-Content-Type (fully-specified 'Content-Type raw))
(vfso "full-Content-Type: ~S~%" full-Content-Type)
(chk '(Content-Type "text/plain;charset=UTF-8")
     full-Content-Type)

;;; x400 ends here
