Created
July 20, 2012 22:22
-
-
Save yamasushi/3153651 to your computer and use it in GitHub Desktop.
http-getから入力ポートをつくりだすための試験場
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use rfc.http) | |
(use gauche.generator) | |
(use util.stream) | |
(define (http-hook-receiver proc) | |
(lambda (code hdrs total retr) | |
(let loop [ ] | |
(receive (port size) (retr) | |
(cond | |
[ (eqv? size 0) #t] | |
[ (or (not size) (> size 0) ) | |
(let loop-rb [(data (read-block size port) ) | |
(req-size size) ] | |
(proc data) ; hook | |
(let1 nrest (- req-size (string-length data)) | |
(if (= nrest 0) | |
(loop) | |
(loop-rb (read-block nrest port) nrest ) ) ) ) ] | |
) ) ) ) ) | |
(define (http-get-stream host path) | |
(iterator->stream | |
(^ (next end) | |
(http-get host path | |
:receiver (http-hook-receiver next) ) | |
(end) | |
) ) ) | |
(define (main args) | |
;(http-get "www.google.com" "/" :receiver (http-hook-receiver (^p (debug-print p) )) ) (exit) | |
(stream-for-each | |
(^q (debug-print q) ) | |
(http-get-stream "www.google.com" "/"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment