Changeset 10767 in project


Ignore:
Timestamp:
05/11/08 19:07:20 (12 years ago)
Author:
sjamaan
Message:

Add support for content-chunking in case of HTTP/1.1 and close connection in HTTP/1.0, because web-unity does not know response content-length and should not really get everything in a string

Location:
release/3/web-unity/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/3/web-unity/trunk/web-unity-spiffy.scm

    r6529 r10767  
    3535  (alist-ref header (http:request-attributes (current-request)) string-ci=? default))
    3636
     37(define wu:original-output-port (make-parameter #f))
     38(define wu:original-error-port  (make-parameter #f))
     39
    3740(define (wu:write-headers)
    38   (parameterize ((current-response-headers (wu:response-headers)))
     41  (parameterize ((current-response-headers (wu:response-headers))
     42                 (current-output-port (wu:original-output-port))
     43                 (current-error-port  (wu:original-error-port)))
    3944    (write-response-header)))
     45
     46;; Try to find out the most efficient way of outputting stuff
     47(define (wu:possibly-chunked dispatcher)
     48  (if (eq? (http:request-protocol (current-request)) 'HTTP/1.1)
     49      (parameterize ((current-output-port (wu:chunked-output-port (current-output-port)))
     50                     (current-error-port (wu:chunked-output-port (current-error-port))))
     51        (wu:set-header! "Transfer-Encoding" "chunked")
     52        (dispatcher)
     53        (fprintf (wu:original-output-port) "0\r\n\r\n"))
     54      (begin
     55        (http:force-close #t)
     56        (dispatcher))))
    4057
    4158(define (wu:run-handler dispatcher)
     
    4966                    (wu:script-filename filename)
    5067                    (wu:response-headers (current-response-headers))
    51                     (wu:response-code (current-response-code)))
    52        (dispatcher)))))
     68                    (wu:response-code (current-response-code))
     69                    (wu:original-output-port (current-output-port))
     70                    (wu:original-error-port (current-error-port)))
     71       (wu:possibly-chunked dispatcher)))))
  • release/3/web-unity/trunk/web-unity.scm

    r6529 r10767  
    4141(load-verbose #f)  ;; No "loading xyz.scm..." in output
    4242
     43; Add http/1.1 chunking to an existing output port
     44(define (wu:chunked-output-port p)
     45  (make-output-port
     46   (lambda (data)
     47     (fprintf p "~X\r\n~A\r\n" (string-length data) data))
     48   void))
     49
    4350;; From Spiffy
    4451(define (wu:single-header? name)
Note: See TracChangeset for help on using the changeset viewer.