tnetconnect.nim 748 B

12345678910111213141516171819202122232425262728293031
  1. discard """
  2. disabled: "i386"
  3. matrix: "-d:ssl"
  4. """
  5. import std/net
  6. from std/strutils import `%`
  7. from stdtest/testutils import enableRemoteNetworking
  8. # bug #15215
  9. proc test() =
  10. let ctx = newContext()
  11. proc fn(url: string) =
  12. let socket = newSocket()
  13. defer: close(socket)
  14. connect(socket, url, Port(443), 5000) # typically 20 could be enough
  15. send(socket, "GET / HTTP/1.0\nHost: $#\nConnection: close\n\n" % [url])
  16. wrapSocket(ctx, socket)
  17. # trying 2 sites makes it more resilent: refs #17458 this could give:
  18. # * Call to 'connect' timed out. [TimeoutError]
  19. # * No route to host [OSError]
  20. try:
  21. fn("www.nim-lang.org")
  22. except TimeoutError, OSError:
  23. fn("www.google.com")
  24. when enableRemoteNetworking:
  25. test()