Mercurial > hg > egg-tcls
comparison fetch_feeds.tcl @ 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 | 5767ef9476e2 |
children | 7192d94f8c28 |
comparison
equal
deleted
inserted
replaced
654:10ea2c1101b3 | 655:4b985abf5aba |
---|---|
22 ### Required utillib.tcl | 22 ### Required utillib.tcl |
23 source [file dirname [info script]]/utillib.tcl | 23 source [file dirname [info script]]/utillib.tcl |
24 | 24 |
25 | 25 |
26 ############################################################################## | 26 ############################################################################## |
27 | |
28 package require sqlite3 | 27 package require sqlite3 |
29 package require http | 28 package require http |
30 | 29 |
31 if {[info exists http_user_agent] && $http_user_agent != ""} { | 30 |
32 ::http::config -urlencoding utf8 -useragent $http_user_agent | 31 ############################################################################## |
33 } else { | 32 ### Utility functions |
34 ::http::config -urlencoding utf8 -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" | 33 |
35 } | 34 proc fetch_sanitize_encoding {uencoding} { |
36 | 35 regsub -- "^\[a-z\]\[a-z\]_\[A-Z\]\[A-Z\]\." $uencoding "" uencoding |
37 if {[info exists http_use_proxy] && $http_use_proxy != 0} { | 36 set uencoding [string tolower $uencoding] |
38 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port | 37 regsub -- "^iso-" $uencoding "iso" uencoding |
39 } | 38 return $uencoding |
40 | 39 } |
41 if {[info exists http_tls_support] && $http_tls_support != 0} { | 40 |
42 package require tls | |
43 ::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] | |
44 } | |
45 | |
46 | |
47 ############################################################################## | |
48 | 41 |
49 proc fetch_dorequest { urlStr urlStatus urlSCode urlCode urlData urlMeta } { | 42 proc fetch_dorequest { urlStr urlStatus urlSCode urlCode urlData urlMeta } { |
50 upvar $urlStatus ustatus | 43 upvar $urlStatus ustatus |
51 upvar $urlSCode uscode | 44 upvar $urlSCode uscode |
52 upvar $urlCode ucode | 45 upvar $urlCode ucode |
210 } | 203 } |
211 | 204 |
212 | 205 |
213 | 206 |
214 | 207 |
208 ############################################################################## | |
215 ### Open database, etc | 209 ### Open database, etc |
210 ############################################################################## | |
211 if {[info exists http_user_agent] && $http_user_agent != ""} { | |
212 ::http::config -urlencoding utf8 -useragent $http_user_agent | |
213 } else { | |
214 ::http::config -urlencoding utf8 -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" | |
215 } | |
216 | |
217 if {[info exists http_use_proxy] && $http_use_proxy != 0} { | |
218 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port | |
219 } | |
220 | |
221 if {[info exists http_tls_support] && $http_tls_support != 0} { | |
222 package require tls | |
223 ::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] | |
224 } | |
225 | |
226 | |
227 | |
216 set nitems 0 | 228 set nitems 0 |
217 set currclock [clock seconds] | 229 set currclock [clock seconds] |
218 global feeds_db | 230 global feeds_db |
219 if {[catch {sqlite3 feeds_db $feeds_db_file} uerrmsg]} { | 231 if {[catch {sqlite3 feeds_db $feeds_db_file} uerrmsg]} { |
220 puts "Could not open SQLite3 database '${feeds_db_file}': ${uerrmsg}" | 232 puts "Could not open SQLite3 database '${feeds_db_file}': ${uerrmsg}" |