mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
* module/web/http.scm (parse-media-type): Parse media types as symbols. (parse-key-value-list, parse-param-component, parse-param-list): Change kons to val-parser. Always parse keys as symbols, and always either cons, if there is a val, or just have the key, if there is no val. Easier to explain and just as correct. (declare-param-list-header!, declare-key-value-list-header!): Adapt to key-list and param-list kons change. ("Cache-Control", "Pragma", "Transfer-Encoding", "Accept", "Expect") ("TE"): Likewise, adapt. ("Content-Type"): Param keys are symbols.
29 lines
1 KiB
Scheme
29 lines
1 KiB
Scheme
;;; Commentary:
|
|
|
|
;;; A simple web server that responds to all requests with the eponymous
|
|
;;; string. Visit http://localhost:8080 to test.
|
|
|
|
;;; Code:
|
|
|
|
(use-modules (web server))
|
|
|
|
;; A handler receives two values as arguments: the request object, and
|
|
;; the request body. It returns two values also: the response object,
|
|
;; and the response body.
|
|
;;
|
|
;; In this simple example we don't actually access the request object,
|
|
;; but if we wanted to, we would use the procedures from the `(web
|
|
;; request)' module. If there is no body given in the request, the body
|
|
;; argument will be false.
|
|
;;
|
|
;; To create a response object, use the `build-response' procedure from
|
|
;; `(web response)'. Here we take advantage of a shortcut, in which we
|
|
;; return an alist of headers for the response instead of returning a
|
|
;; proper response object. In this case, a response object will be made
|
|
;; for us with a 200 OK status.
|
|
;;
|
|
(define (handler request body)
|
|
(values '((content-type . (text/plain)))
|
|
"Hello, World!"))
|
|
|
|
(run-server handler)
|