aboutsummaryrefslogtreecommitdiff
path: root/weeb/response.scm
blob: 71b81673a6632b9e3ab487003bd5862e1e8d2071 (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
;;; Weeb --- Web microframework for GNU Guile
;;; Copyright © 2026 Jakob Kreuze <zerodaysfordays@sdf.org>
;;;
;;; This file is part of Weeb.
;;;
;;; Weeb is free software: you can redistribute it and/or modify it
;;; under the terms of the GNU Affero General Public License as
;;; published by the Free Software Foundation, either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; Weeb 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 Affero General
;;; Public License for more details.
;;;
;;; You should have received a copy of the GNU Affero General Public
;;; License along with Weeb. If not, see <https://www.gnu.org/licenses/>.

(define-module (weeb response)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (weeb struct)
  #:use-module (weeb sxml)
  #:export (<response>
            any->response))

(define-struct <response>
  code headers body)

(define (any->response data)
  (match data
    ((? (cut instance-of? <> <response>)) data)
    ((? string?) (make-struct <response> 200 '() data))
    ((code body)
     ;; (assert (and (list? headers) (string? body)))
     (make-struct <response> code '() body))
    (_ (error "could not coerce data to <response>" data))))

© 2015 - 2026 Jakob L. Kreuze