2020-11-15 23:54:47 +03:00
|
|
|
// Simple raw HTTP head request
|
|
|
|
import net
|
|
|
|
import time
|
|
|
|
import io
|
|
|
|
|
2020-12-15 18:39:11 +03:00
|
|
|
fn main() {
|
|
|
|
// Make a new connection
|
2021-02-16 23:53:46 +03:00
|
|
|
mut conn := net.dial_tcp('google.com:80') ?
|
2020-12-15 18:39:11 +03:00
|
|
|
// Simple http HEAD request for a file
|
2021-02-16 23:53:46 +03:00
|
|
|
conn.write_str('GET /index.html HTTP/1.0\r\n\r\n') ?
|
2020-12-15 18:39:11 +03:00
|
|
|
// Wrap in a buffered reader
|
|
|
|
mut r := io.new_buffered_reader(reader: io.make_reader(conn))
|
|
|
|
for {
|
2021-02-16 23:53:46 +03:00
|
|
|
l := r.read_line() or { break }
|
2020-12-15 18:39:11 +03:00
|
|
|
println('$l')
|
|
|
|
// Make it nice and obvious that we are doing this line by line
|
2021-02-21 18:05:03 +03:00
|
|
|
time.wait(100 * time.millisecond)
|
2020-11-15 23:54:47 +03:00
|
|
|
}
|
2021-02-16 23:53:46 +03:00
|
|
|
}
|