changeset 655:4b985abf5aba

fetch_feeds: Move HTTP initialization to end of script.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 19 Feb 2021 19:29:51 +0200
parents 10ea2c1101b3
children 7192d94f8c28
files fetch_feeds.tcl
diffstat 1 files changed, 28 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_feeds.tcl	Wed Feb 17 12:10:14 2021 +0200
+++ b/fetch_feeds.tcl	Fri Feb 19 19:29:51 2021 +0200
@@ -24,27 +24,20 @@
 
 
 ##############################################################################
-
 package require sqlite3
 package require http
 
-if {[info exists http_user_agent] && $http_user_agent != ""} {
-  ::http::config -urlencoding utf8 -useragent $http_user_agent
-} else {
-  ::http::config -urlencoding utf8 -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
+
+##############################################################################
+### Utility functions
+
+proc fetch_sanitize_encoding {uencoding} {
+  regsub -- "^\[a-z\]\[a-z\]_\[A-Z\]\[A-Z\]\." $uencoding "" uencoding
+  set uencoding [string tolower $uencoding]
+  regsub -- "^iso-" $uencoding "iso" uencoding
+  return $uencoding
 }
 
-if {[info exists http_use_proxy] && $http_use_proxy != 0} {
-  ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port
-}
-
-if {[info exists http_tls_support] && $http_tls_support != 0} {
-  package require tls
-  ::http::register https 443 [list ::tls::socket -request true -require true -ssl2 false -ssl3 false -tls1 true -tls1.1 true -tls1.2 true -cadir $http_tls_cadir -autoservername true]
-}
-
-
-##############################################################################
 
 proc fetch_dorequest { urlStr urlStatus urlSCode urlCode urlData urlMeta } {
   upvar $urlStatus ustatus
@@ -212,7 +205,26 @@
 
 
 
+##############################################################################
 ### Open database, etc
+##############################################################################
+if {[info exists http_user_agent] && $http_user_agent != ""} {
+  ::http::config -urlencoding utf8 -useragent $http_user_agent
+} else {
+  ::http::config -urlencoding utf8 -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
+}
+
+if {[info exists http_use_proxy] && $http_use_proxy != 0} {
+  ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port
+}
+
+if {[info exists http_tls_support] && $http_tls_support != 0} {
+  package require tls
+  ::http::register https 443 [list ::tls::socket -request true -require true -ssl2 false -ssl3 false -tls1 true -tls1.1 true -tls1.2 true -cadir $http_tls_cadir -autoservername true]
+}
+
+
+
 set nitems 0
 set currclock [clock seconds]
 global feeds_db