GNU Info

Info Node: (slib.info)HTTP and CGI

(slib.info)HTTP and CGI


Next: URI Prev: HTML Tables Up: Textual Conversion Packages
Enter node , (file) or (file)node

HTTP and CGI
============

  `(require 'http)' or `(require 'cgi)'

 - Function: http:header alist
     Returns a string containing lines for each element of ALIST; the
     `car' of which is followed by `: ', then the `cdr'.

 - Function: http:content alist body ...
     Returns the concatenation of strings BODY with the `(http:header
     ALIST)' and the `Content-Length' prepended.

 - Variable: *http:byline*
     String appearing at the bottom of error pages.

 - Function: http:error-page status-code reason-phrase html-string ...
     STATUS-CODE and REASON-PHRASE should be an integer and string as
     specified in `RFC 2068'.  The returned page (string) will show the
     STATUS-CODE and REASON-PHRASE and any additional HTML-STRINGS ...;
     with *HTTP:BYLINE* or SLIB's default at the bottom.

 - Function: http:forwarding-page title delay uri html-string ...
     The string or symbol TITLE is the page title.  DELAY is a
     non-negative integer.  The HTML-STRINGS ... are typically used to
     explain to the user why this page is being forwarded.

     `http:forwarding-page' returns an HTML string for a page which
     automatically forwards to URI after DELAY seconds.  The returned
     page (string) contains any HTML-STRINGS ... followed by a manual
     link to URI, in case the browser does not forward automatically.

 - Function: http:serve-query serve-proc input-port output-port
     reads the "URI" and "query-string" from INPUT-PORT.  If the query
     is a valid `"POST"' or `"GET"' query, then `http:serve-query' calls
     SERVE-PROC with three arguments, the REQUEST-LINE, QUERY-STRING,
     and HEADER-ALIST.  Otherwise, `http:serve-query' calls SERVE-PROC
     with the REQUEST-LINE, #f, and HEADER-ALIST.

     If SERVE-PROC returns a string, it is sent to OUTPUT-PORT.  If
     SERVE-PROC returns a list, then an error page with number 525 and
     strings from the list.  If SERVE-PROC returns #f, then a `Bad
     Request' (400) page is sent to OUTPUT-PORT.

     Otherwise, `http:serve-query' replies (to OUTPUT-PORT) with
     appropriate HTML describing the problem.

  This example services HTTP queries from PORT-NUMBER:

     (define socket (make-stream-socket AF_INET 0))
     (and (socket:bind socket port-number) ; AF_INET INADDR_ANY
          (socket:listen socket 10)        ; Queue up to 10 requests.
          (dynamic-wind
              (lambda () #f)
              (lambda ()
                (do ((port (socket:accept socket) (socket:accept socket)))
                    (#f)
                  (let ((iport (duplicate-port port "r"))
                        (oport (duplicate-port port "w")))
                    (http:serve-query build:serve iport oport)
                    (close-port iport)
                    (close-port oport))
                  (close-port port)))
              (lambda () (close-port socket))))

 - Function: cgi:serve-query serve-proc
     reads the "URI" and "query-string" from `(current-input-port)'.
     If the query is a valid `"POST"' or `"GET"' query, then
     `cgi:serve-query' calls SERVE-PROC with three arguments, the
     REQUEST-LINE, QUERY-STRING, and HEADER-ALIST.  Otherwise,
     `cgi:serve-query' calls SERVE-PROC with the REQUEST-LINE, #f, and
     HEADER-ALIST.

     If SERVE-PROC returns a string, it is sent to
     `(current-input-port)'.  If SERVE-PROC returns a list, then an
     error page with number 525 and strings from the list.  If
     SERVE-PROC returns #f, then a `Bad Request' (400) page is sent to
     `(current-input-port)'.

     Otherwise, `cgi:serve-query' replies (to `(current-input-port)')
     with appropriate HTML describing the problem.

 - Function: make-query-alist-command-server rdb command-table
 - Function: make-query-alist-command-server rdb command-table #t
     Returns a procedure of one argument.  When that procedure is called
     with a QUERY-ALIST (as returned by `uri:decode-query', the value
     of the `*command*' association will be the command invoked in
     COMMAND-TABLE.  If `*command*' is not in the QUERY-ALIST then the
     value of `*suggest*' is tried.  If neither name is in the
     QUERY-ALIST, then the literal value `*default*' is tried in
     COMMAND-TABLE.

     If optional third argument is non-false, then the command is called
     with just the parameter-list; otherwise, command is called with the
     arguments described in its table.


automatically generated by info2www version 1.2.2.9