Created
January 31, 2013 21:51
-
-
Save anonymous/4686849 to your computer and use it in GitHub Desktop.
download big with rebol3
This file contains 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
rebol[] | |
REBOL [Title: "Simple Async HTTP"] | |
send-http-request: func [port] [ | |
write port to-binary ajoin [ | |
"GET " port/spec/path " HTTP/1.0" crlf | |
"Host: " port/spec/host crlf | |
crlf | |
] | |
] | |
;!! | |
done: false | |
read-http: func [ | |
"Async HTTP reader" | |
url [url!] | |
/local spec port | |
][ | |
spec: probe decode-url url | |
spec/2: to-lit-word 'tcp | |
port: open spec | |
port/awake: func [event] [ | |
;print ["Awake-event:" event/type] | |
switch/default event/type [ | |
lookup [open event/port] | |
connect [send-http-request event/port] | |
wrote [read event/port] | |
read [ | |
;print ["Read" length? event/port/data "bytes"] | |
read event/port | |
] | |
close [ | |
;!! | |
done: true | |
return true | |
] | |
] [ | |
print ["Unexpected event:" event/type] | |
close event/port | |
return true | |
] | |
false ; returned | |
] | |
port | |
] | |
print "reading..." | |
;!! | |
; rp: read-http http://www.rebol.net/ | |
rp: read-http http://netcologne.dl.sourceforge.net/project/warzone2100/releases/3.1.0/warzone2100-3.1.0.tar.xz | |
;!! | |
while[not done][wait [rp 1] print ["beep " length? rp/data]] | |
close rp | |
print ["finished " length? rp/data] | |
;print to-string rp/data | |
data: copy/part find/tail rp/data #{0d0a0d0a} tail rp/data | |
;write %rebol-net.html data | |
;browse %rebol-net.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment