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