2019-12-30 07:42:23 +03:00
|
|
|
import net.http
|
2019-07-31 14:38:24 +03:00
|
|
|
|
2019-08-06 14:57:58 +03:00
|
|
|
fn test_http_get() {
|
2020-01-16 20:16:11 +03:00
|
|
|
// $if !network ? { return }
|
2019-08-22 22:48:31 +03:00
|
|
|
assert http.get_text('https://vlang.io/version') == '0.1.5'
|
|
|
|
println('http ok')
|
|
|
|
}
|
2019-08-06 14:57:58 +03:00
|
|
|
|
2020-01-16 20:16:11 +03:00
|
|
|
fn test_http_get_from_vlang_utc_now() {
|
|
|
|
// $if !network ? { return }
|
2019-08-21 20:04:06 +03:00
|
|
|
urls := ['http://vlang.io/utc_now', 'https://vlang.io/utc_now']
|
|
|
|
for url in urls {
|
|
|
|
println('Test getting current time from $url by http.get')
|
|
|
|
res := http.get(url) or { panic(err) }
|
|
|
|
assert 200 == res.status_code
|
|
|
|
assert res.text.len > 0
|
|
|
|
assert res.text.int() > 1566403696
|
|
|
|
println('Current time is: ${res.text.int()}')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_public_servers() {
|
2020-01-16 20:16:11 +03:00
|
|
|
// $if !network ? { return }
|
2019-08-22 22:48:31 +03:00
|
|
|
urls := [
|
2019-08-21 20:04:06 +03:00
|
|
|
'http://github.com/robots.txt',
|
|
|
|
'http://google.com/robots.txt',
|
2019-08-22 22:48:31 +03:00
|
|
|
'http://yahoo.com/robots.txt',
|
2019-08-21 20:04:06 +03:00
|
|
|
'https://github.com/robots.txt',
|
|
|
|
'https://google.com/robots.txt',
|
2019-08-22 22:48:31 +03:00
|
|
|
'https://yahoo.com/robots.txt',
|
2019-08-21 20:04:06 +03:00
|
|
|
]
|
|
|
|
for url in urls {
|
|
|
|
println('Testing http.get on public url: $url ')
|
|
|
|
res := http.get( url ) or { panic(err) }
|
|
|
|
assert 200 == res.status_code
|
|
|
|
assert res.text.len > 0
|
|
|
|
}
|
|
|
|
}
|