Next: , Previous: , Up: Usage Examples   [Contents][Index]


4.12 Chunked Transfer Encoding

Similarly, HTTP Responses may be sent using the “chunked” transfer encoding by passing the appropriate HTTP header to ws-response-header. Any further data sent to the process using ws-send will automatically be appropriately encoded for chunked transfer.

;;; transfer-encoding-chunked.el -- chunked transfer encoding
(ws-start
 (lambda (request)
   (let ((s "
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam
nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis
natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus. Nulla posuere. Donec vitae dolor. Nullam tristique
diam non turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam
vestibulum accumsan nisl.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam
nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis
natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus. Nulla posuere. Donec vitae dolor. Nullam tristique
diam non turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam
vestibulum accumsan nisl.
"))
     (with-slots (process headers) request
       (ws-response-header process 200
         '("Content-type" . "text/plain; charset=utf-8")
         '("Transfer-Encoding" . "chunked"))
       (ws-send process s) (sit-for 0.5)
       (ws-send process s) (sit-for 0.5)
       (ws-send process s) (sit-for 0.5)
       (ws-send process s))))
 9017)