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
|
2022-10-16 09:28:57 +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
|
2022-10-16 09:28:57 +03:00
|
|
|
conn.write_string('GET /index.html HTTP/1.0\r\n\r\n')!
|
2020-12-15 18:39:11 +03:00
|
|
|
// Wrap in a buffered reader
|
2021-05-13 10:26:10 +03:00
|
|
|
mut r := io.new_buffered_reader(reader: conn)
|
2020-12-15 18:39:11 +03:00
|
|
|
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-27 20:41:06 +03:00
|
|
|
time.sleep(100 * time.millisecond)
|
2020-11-15 23:54:47 +03:00
|
|
|
}
|
2021-02-16 23:53:46 +03:00
|
|
|
}
|