Posted to tcl by aspect at Sun Oct 18 06:42:42 GMT 2015view raw

  1. # Tcl: 8.6.4
  2. # http: 2.8.9
  3. # tls: 1.6.7 (OpenSSL 1.0.2d 9 Jul 2015)
  4. # Fetching https://google.com/ ...
  5. # OK! 261 bytes
  6. # Fetching https://1337x.to/ ...
  7. # ERROR: error flushing "sock24ad900": connection reset by peer
  8. # Fetching https://google.com/ ...
  9. # OK! 261 bytes
  10.  
  11. puts "Tcl: [package require Tcl]"
  12. puts "http: [package require http]"
  13. puts "tls: [package require tls] ([tls::version])"
  14. http::register https 443 tls::socket
  15.  
  16. # if this is omitted, the message appears on stderr during the next request *after* 1337x.to:
  17. # SSL channel "sock1829830": error: tlsv1 alert internal error
  18. ::tls::init -command ::tls_cb
  19.  
  20. proc tls_cb {what args} {
  21. #puts "TLS: $what $args"
  22. return 1 ;# cert OK, for "verify"
  23. }
  24.  
  25. # wrapper with error handling
  26. proc fetch {url} {
  27. puts "Fetching $url ..."
  28. try {
  29. set t [::http::geturl $url]
  30. set d [::http::data $t]
  31. ::http::cleanup $t
  32. puts "OK! [string length $d] bytes"
  33. } on error {e o} {
  34. puts "ERROR: $e"
  35. }
  36. }
  37.  
  38. fetch https://google.com/ ;# this succeeds
  39. fetch https://1337x.to/ ;# this fails
  40. fetch https://google.com/ ;# then a (harmless?) error is emitted here
  41.