mIRC Home    About    Download    Register    News    Help

Print Thread
$urlget() head request returns no target &binvar #266613 04/01/20 04:26 PM
Joined: Feb 2003
Posts: 2,685
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,685
When requesting an $urlget() with the 'bh' (binvar; HEAD) options, there is no target binvar created within the callback alias, as there is with 'bg' (binvar; GET).
This seems invalid, because $urlget(%id).target will declare a &binvar name, but that binvar does not exist. It causes $bvar(&binvar,1-).text to throw an erroneous error.

I'm of the opinion that the &target binvar should be populated by the header reply when requesting the HEAD method.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: $urlget() head request returns no target &binvar [Re: Raccoon] #266615 04/01/20 08:47 PM
Joined: Dec 2002
Posts: 4,691
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,691
Thanks for your bug report. This is intentional. The HEAD result is only ever returned in $urlget().reply.

Re: $urlget() head request returns no target &binvar [Re: Khaled] #266618 05/01/20 12:34 AM
Joined: Feb 2003
Posts: 2,685
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,685
Cool beans. So how is the script supposed to know that the &target binvar exists or does not exist, to prevent it from tripping errors?

Authors can either anticipate the existence of the &target binvar, per ($urlget(%id).target == &target), or lose faith in the universe, not both.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: $urlget() head request returns no target &binvar [Re: Raccoon] #266629 06/01/20 06:07 PM
Joined: Dec 2002
Posts: 4,691
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,691
Quote
Cool beans. So how is the script supposed to know that the &target binvar exists or does not exist, to prevent it from tripping errors?

The only method is to use $bvar() to check if it exists. The .target property only tells you what was requested by $urlget(), it does not guarantee that the target file or binvar exists. In my scripts, I use $isfile() and $bvar() to check these.

Re: $urlget() head request returns no target &binvar [Re: Khaled] #266631 06/01/20 08:26 PM
Joined: Feb 2003
Posts: 2,685
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,685
Ok, so Inline Example:
Code
echo -a $iif($bvar($urlget($1).target),$bvar($v1,1-).text)

Structured Example:
Code
var %id = $1, %binvar = $urlget(%id).target, %target
if ($bvar(%binvar)) {
  var %target = $bvar(%binvar,1-).text
}
echo -a %target


Well. At least I won lunch.
Good philosophy, see good in bad, I like!