Changeset 29114 in project


Ignore:
Timestamp:
06/18/13 02:00:18 (8 years ago)
Author:
Ivan Raikov
Message:

cgi: added simple-input->string convenience function

Location:
release/4/cgi/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/cgi/trunk/protocol.scm

    r29090 r29114  
    1616         request-inputs request-body
    1717         input-value input-ct input-filename
     18         simple-input->string
    1819         DocumentResponse
    1920         LocalRedirResponse
     
    3435;; The value of an input parameter, and some metadata.
    3536(define-record-type input
    36   (Input value content-type filename)
     37  (Input value filename content-type)
    3738  input?
    3839  (value        input-value)
     
    296297(define (simple-input v)  (Input v #f default-input-type))
    297298
     299(define (simple-input->string v)
     300  (cases input v
     301         (Input (val fn ct)
     302                (match ct (("text" _ _)  val)
     303                       (else #f)))
     304         (else #f)))
     305               
    298306
    299307;; Gets inputs from the query string.
     
    324332          (let-values (((k v) (span (lambda (c) (not (char=? c #\=))) kv)))
    325333            (recur (if (null? rest) rest (cdr rest))
    326                    (cons (list (list->string (uri-char-decode k))
    327                                (list->string (if (null? v) v (uri-char-decode (cdr v)))))
    328                          ax))
     334                   (cons
     335                    (cons (string->symbol (list->string (uri-char-decode k)))
     336                          (list->string (if (null? v) v (uri-char-decode (cdr v)))))
     337                    ax))
    329338            ))
    330339        ))
     
    334343;; Decodes application\x-www-form-urlencoded inputs.
    335344(define (form-input qs)
    336   (map (lambda (nv) (list (car nv) (simple-input (cadr nv))))
     345  (map (lambda (nv) (cons (car nv) (simple-input (cdr nv))))
    337346       (form-urldecode (map integer->char (byte-blob->list qs)))))
    338347
  • release/4/cgi/trunk/tests/processform.scm

    r29090 r29114  
    22
    33(define (action request)
    4   (DocumentResponse
    5    `((Content-type . "text/plain;charset=us-ascii"))
    6    `("Hello, " ,(request-inputs request) )
     4  (let ((inputs (request-inputs request)))
     5    (DocumentResponse
     6     `((Content-type . "text/plain;charset=us-ascii"))
     7     `(,(sprintf "Hello, ~A (~A)"
     8                 (simple-input->string (alist-ref 'name inputs))
     9                 (simple-input->string (alist-ref 'email inputs))
     10                 )))
    711   ))
    812
Note: See TracChangeset for help on using the changeset viewer.