aboutsummaryrefslogtreecommitdiff
path: root/weeb
diff options
context:
space:
mode:
authorJakob L. Kreuze2026-07-10 17:51:56 -0400
committerJakob L. Kreuze2026-07-10 17:51:56 -0400
commit852eb83cd9e78a8428d4a1175ed162b0e92e4681 (patch)
treed43fa47df449a8764acd3cf6ab6b5d2f97e23d61 /weeb
parente2a4247c3a62e02c9709b4f6bf62fae1f9f8c1e0 (diff)
Primordial responder loop
Diffstat (limited to 'weeb')
-rw-r--r--weeb/main.scm56
1 files changed, 56 insertions, 0 deletions
diff --git a/weeb/main.scm b/weeb/main.scm
new file mode 100644
index 0000000..2fc6df1
--- /dev/null
+++ b/weeb/main.scm
@@ -0,0 +1,56 @@
+;;; 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 main)
+ #:use-module (ice-9 match)
+ #:use-module (ice-9 regex)
+ #:use-module (srfi srfi-1)
+ #:use-module (weeb fcgi)
+ #:use-module (weeb request)
+ #:use-module (weeb struct)
+ #:export (weeb main))
+
+(define (receive-request)
+ (define string->method
+ (match-lambda
+ (("GET" 'GET)
+ ("POST" 'POST))))
+ ;; According to RFC 9110, header names must be treated as case-insensitive.
+ (define headers
+ (filter-map
+ (lambda (var)
+ (let ((match-object (string-match "HTTP_(.*)=(.*)" var)))
+ (if match-object
+ `(,(string->symbol
+ (string-downcase
+ (string-map (lambda (c) (if (char=? c #\_) #\- c))
+ (match:substring match-object 1))))
+ .
+ ,(match:substring match-object 2))
+ #f)))
+ (environ)))
+ (let* ((method (getenv "REQUEST_METHOD"))
+ (uri (getenv "REQUEST_URI")))
+ (make-struct <request> method uri '() headers (fcgi-read))))
+
+(define (run-server)
+ (while (zero? (fcgi-accept))
+ (let ((request (receive-request)))
+ (with-accessors (request method uri headers body)
+ (fcgi-display "Content-type: text/html\r\n\r\n")
+ (fcgi-display (format #f "~a" headers))))))

© 2015 - 2026 Jakob L. Kreuze