Changeset 14978 in project


Ignore:
Timestamp:
06/11/09 22:22:07 (11 years ago)
Author:
sjamaan
Message:

Implement SAFE? and IDEMPOTENT? predicates for methods/requests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/intarweb/trunk/intarweb.scm

    r14856 r14978  
    3939   headers? headers->list http-name->symbol symbol->http-name
    4040   header-parsers header-unparsers unparse-header unparse-headers
    41    keep-alive?
     41   safe-methods safe? idempotent-methods idempotent? keep-alive?
    4242   
    4343   make-request request? request-major request-major-set!
     
    4646   request-headers request-headers-set! request-port request-port-set!
    4747   update-request set-request!
    48    
     48
    4949   request-parsers read-request request-unparsers write-request read-headers
    5050   http-0.9-request-parser http-1.x-request-parser
     
    235235                           (peek-char port)
    236236                           #!eof)))))
     237
     238(define safe-methods
     239  (make-parameter '(GET HEAD)))
     240
     241;; RFC2616, Section 9.1.1
     242(define (safe? obj)
     243  (let ((method (if (request? obj) (request-method obj) obj)))
     244    (not (not (member method (safe-methods))))))
     245
     246(define idempotent-methods
     247  (make-parameter '(GET HEAD PUT DELETE OPTIONS TRACE)))
     248
     249;; RFC2616, Section 9.1.2
     250(define (idempotent? obj)
     251  (let ((method (if (request? obj) (request-method obj) obj)))
     252    (not (not (member method (idempotent-methods))))))
    237253
    238254(define (keep-alive? obj)
Note: See TracChangeset for help on using the changeset viewer.