2019-12-30 05:42:23 +01:00
|
|
|
import net.http
|
2019-07-31 13:38:24 +02:00
|
|
|
|
2019-08-06 13:57:58 +02:00
|
|
|
fn test_http_get() {
|
2020-10-15 15:17:52 +02:00
|
|
|
$if !network ? {
|
|
|
|
return
|
|
|
|
}
|
2019-08-22 21:48:31 +02:00
|
|
|
assert http.get_text('https://vlang.io/version') == '0.1.5'
|
|
|
|
println('http ok')
|
|
|
|
}
|
2019-08-06 13:57:58 +02:00
|
|
|
|
2020-01-16 18:16:11 +01:00
|
|
|
fn test_http_get_from_vlang_utc_now() {
|
2020-10-15 15:17:52 +02:00
|
|
|
$if !network ? {
|
|
|
|
return
|
|
|
|
}
|
2019-08-21 19:04:06 +02: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')
|
2021-06-14 09:08:41 +02:00
|
|
|
res := http.get(url) or { panic(err) }
|
2021-07-24 19:47:45 +02:00
|
|
|
assert res.status() == .ok
|
2022-05-29 19:27:18 +02:00
|
|
|
assert res.body.len > 0
|
|
|
|
assert res.body.int() > 1566403696
|
|
|
|
println('Current time is: $res.body.int()')
|
2019-08-21 19:04:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_public_servers() {
|
2020-10-15 15:17:52 +02:00
|
|
|
$if !network ? {
|
|
|
|
return
|
|
|
|
}
|
2019-08-22 21:48:31 +02:00
|
|
|
urls := [
|
2019-08-21 19:04:06 +02:00
|
|
|
'http://github.com/robots.txt',
|
|
|
|
'http://google.com/robots.txt',
|
|
|
|
'https://github.com/robots.txt',
|
|
|
|
'https://google.com/robots.txt',
|
2020-10-15 15:17:52 +02:00
|
|
|
// 'http://yahoo.com/robots.txt',
|
|
|
|
// 'https://yahoo.com/robots.txt',
|
2019-08-21 19:04:06 +02:00
|
|
|
]
|
|
|
|
for url in urls {
|
|
|
|
println('Testing http.get on public url: $url ')
|
2021-06-14 09:08:41 +02:00
|
|
|
res := http.get(url) or { panic(err) }
|
2021-07-24 19:47:45 +02:00
|
|
|
assert res.status() == .ok
|
2022-05-29 19:27:18 +02:00
|
|
|
assert res.body.len > 0
|
2019-08-21 19:04:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-12 14:52:39 +01:00
|
|
|
|
|
|
|
fn test_relative_redirects() {
|
2020-10-15 15:17:52 +02:00
|
|
|
$if !network ? {
|
|
|
|
return
|
|
|
|
} $else {
|
|
|
|
return
|
|
|
|
} // tempfix periodic: httpbin relative redirects are broken
|
2021-06-14 09:08:41 +02:00
|
|
|
res := http.get('https://httpbin.org/relative-redirect/3?abc=xyz') or { panic(err) }
|
2021-07-24 19:47:45 +02:00
|
|
|
assert res.status() == .ok
|
2022-05-29 19:27:18 +02:00
|
|
|
assert res.body.len > 0
|
|
|
|
assert res.body.contains('"abc": "xyz"')
|
2020-02-12 14:52:39 +01:00
|
|
|
}
|