147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# URI that was HTTPS? Otherwise, a script error will result.
#
variable allowInsecureRedirect; # DEFAULT: false
if {![info exists allowInsecureRedirect]} then {
set allowInsecureRedirect false
}
}
#
# NOTE: This procedure was stolen from the "common.tcl" script. It is
# designed to emit a message to the console. The channel argument
# is the channel where the message should be written. The string
# argument is the content of the message to emit. If the channel
|
>
>
>
>
>
>
>
>
>
>
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# URI that was HTTPS? Otherwise, a script error will result.
#
variable allowInsecureRedirect; # DEFAULT: false
if {![info exists allowInsecureRedirect]} then {
set allowInsecureRedirect false
}
#
# NOTE: How long should we wait for the HTTP request to complete? This
# value is the number of milliseconds.
#
variable timeoutGetUrl; # DEFAULT: 0
if {![info exists timeoutGetUrl]} then {
set timeoutGetUrl 0
}
}
#
# NOTE: This procedure was stolen from the "common.tcl" script. It is
# designed to emit a message to the console. The channel argument
# is the channel where the message should be written. The string
# argument is the content of the message to emit. If the channel
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
#
# NOTE: This variable is used to keep track of the currently scheduled
# (i.e. pending) [after] event.
#
variable afterForPageProgress
#
# NOTE: This procedure requires the modern version of the HTTP package,
# which is typically included with the Tcl core distribution.
#
package require http 2.0
#
|
>
>
>
>
>
>
|
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
#
# NOTE: This variable is used to keep track of the currently scheduled
# (i.e. pending) [after] event.
#
variable afterForPageProgress
#
# NOTE: This variable is used to determine the timeout milliseconds for
# HTTP requests.
#
variable timeoutGetUrl
#
# NOTE: This procedure requires the modern version of the HTTP package,
# which is typically included with the Tcl core distribution.
#
package require http 2.0
#
|
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
# NOTE: Emit important diagnostic information related to this
# HTTP request here. This may be enhanced in the future.
#
pageLog [appendArgs \
"attempting to download URL \"" $uri \"...]
}
set token [eval ::http::geturl [list $uri] $args]
#
# NOTE: Grab the HTTP response code and data now as they are needed
# in almost all cases.
#
set code [::http::ncode $token]; set data [::http::data $token]
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
# NOTE: Emit important diagnostic information related to this
# HTTP request here. This may be enhanced in the future.
#
pageLog [appendArgs \
"attempting to download URL \"" $uri \"...]
}
#
# NOTE: Build the (optional?) list of options for the HTTP call.
#
set localArgs [list]
if {$timeoutGetUrl != 0} then {
lappend localArgs -timeout $timeoutGetUrl; # milliseconds
}
if {[llength $args] > 0} then {
eval lappend localArgs $args
}
#
# NOTE: Attempt to perform the actual HTTP request. This can fail
# in an almost unlimited number of ways, which is fun.
#
set token [eval ::http::geturl [list $uri] $localArgs]
#
# NOTE: Grab the HTTP status. It must be "ok" in order to proceed.
#
set status [::http::status $token]
if {$status ne "ok"} then {
error [appendArgs \
"bad HTTP status \"" $status "\" is not \"ok\""]
}
#
# NOTE: Grab the HTTP response code and data now as they are needed
# in almost all cases.
#
set code [::http::ncode $token]; set data [::http::data $token]
|