aboutsummaryrefslogtreecommitdiff
path: root/prototypes/c3b2/web/helpers.scm
diff options
context:
space:
mode:
authorAnonymized <anonymous@example.com>2018-01-20 00:04:03 +0100
committerAnonymized <anonymous@example.com>2018-01-20 00:04:03 +0100
commitc0cb936b41bc9ecb6e1ccae1fad3815cc095aae0 (patch)
tree693e0f9bec4a1cb214575c62c3ba41856b30b401 /prototypes/c3b2/web/helpers.scm
parent2a53ce66dbd2383ec323b4edac486fee3b54af21 (diff)
downloadgnunet-guile2-c0cb936b41bc9ecb6e1ccae1fad3815cc095aae0.tar.gz
gnunet-guile2-c0cb936b41bc9ecb6e1ccae1fad3815cc095aae0.zip
add web boilerplate for c3b2 prototype
Diffstat (limited to 'prototypes/c3b2/web/helpers.scm')
-rw-r--r--prototypes/c3b2/web/helpers.scm50
1 files changed, 50 insertions, 0 deletions
diff --git a/prototypes/c3b2/web/helpers.scm b/prototypes/c3b2/web/helpers.scm
new file mode 100644
index 0000000..597d6a0
--- /dev/null
+++ b/prototypes/c3b2/web/helpers.scm
@@ -0,0 +1,50 @@
1;;; Copyright © 2015-2017 Amirouche Boubekki <amirouche@hypermove.net>
2;;
3;; This program is free software: you can redistribute it and/or modify
4;; it under the terms of the GNU General Public License as published by
5;; the Free Software Foundation, either version 3 of the License, or
6;; (at your option) any later version.
7
8;; This program 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
11;; GNU General Public License for more details.
12
13;; You should have received a copy of the GNU General Public License
14;; along with this program. If not, see <http://www.gnu.org/licenses/>.
15(define-module (web helpers))
16
17;; stdlib
18(use-modules (web request))
19(use-modules (web response))
20(use-modules (web uri))
21
22;; local
23(use-modules (web html))
24
25
26;;; helpers
27
28(define-public (request-path-components request)
29 "Split the URI path of REQUEST into a list of component strings. For
30example: \"/foo/bar\" yields '(\"foo\" \"bar\")."
31 (split-and-decode-uri-path (uri-path (request-uri request))))
32
33(define-public (render-html sxml)
34 (values '((content-type . (text/html)))
35 (lambda (port)
36 (sxml->html sxml port))))
37
38(define-public (forbidden)
39 (values (build-response #:code 403)
40 "Forbidden"))
41
42(define-public (not-found uri)
43 (values (build-response #:code 404)
44 (string-append "Resource not found: " uri)))
45
46(define-public (redirect uri)
47 (values (build-response #:code 303 #:headers `((Location . ,uri))) ""))
48
49(define-public (error)
50 (values (build-response #:code 500)))