summary refs log tree commit diff stats
path: root/tests/stdlib/tnetconnect.nim
blob: b745457107d45eb0d6d1ced3f0a1d5e10477ddeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
discard """
  matrix: "-d:ssl"
"""

import std/net
from std/strutils import `%`

# bug #15215
proc test() =
  let ctx = newContext()

  proc fn(url: string) =
    let socket = newSocket()
    defer: close(socket)
    connect(socket, url, Port(443), 5000) # typically 20 could be enough
    send(socket, "GET / HTTP/1.0\nHost: $#\nConnection: close\n\n" % [url])
    wrapSocket(ctx, socket)

  # trying 2 sites makes it more resilent: refs #17458 this could give:
  # Error: unhandled exception: Call to 'connect' timed out. [TimeoutError]
  try:
    fn("www.nim-lang.org")
  except TimeoutError:
    fn("www.google.com")

test()