So, I've written a function that looks at one URL at a time and returns true
or false depending on its accessibility. Now, my problem is that the result
is returned only when all (and that means potentially many) URLs have been
checked. Isn't there a way to "force a write"? I'm not sure I'm expressing
myself correctly, but hopefully you'll understand what I mean. Thanks.
(: consider this: if the timeout is 10 seconds, and I have three "bad" URLs,
I may have to wait up to 30 seconds before seeing the results, isn't there a
way to see a result every ten seconds instead? :)
for $url in $urls
return <xh:li>{$url}: {utils:http-resource-available($url,
$timeout)}</xh:li>
(: function that checks accessibility of a URL, written for DOIs which are
"placeholder" URLs which forward to the real URL :)
declare function utils:http-resource-available
($doi as xs:string, $oldtimeout as xs:integer?) as xs:boolean
{
try {
let $timeout := if ($oldtimeout) then $oldtimeout else 10
let $head := xdmp:http-get(fn:concat($utils:doi-resolver, $doi),
<options
xmlns="xdmp:http"><timeout>{$timeout}</timeout></options>)
let $code := $head//xdh:code cast as xs:integer
let $location := $head//xdh:location
return ((fn:contains($location, $utils:location-part-to-match)) and
($code < 400)) (: we want 3XX or 2XX? :)
} catch ($ex) {
if ($ex/error:code eq 'SVC-SOCRECV')
then
fn:false()
else
xdmp:rethrow()
}
};
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general