[ic] HTTP POST, getting a bit closer but not there yet

Mike Heins interchange-users@icdevgroup.org
Fri Feb 14 11:52:01 2003


Quoting Marc Brevoort (marc.brevoort@armazemdedados.com):
> On Thu, 2003-02-13 at 20:42, Dan Browning wrote:
> > >I've modified this to accept url and content, and tried to get it
> > >working as tag and as subroutine included from catalog.cfg, but to my
> > >frustration, all I'm getting is "Safe: require trapped by operation
> > >mask" anytime I try to 'use LWP::UserAgent'.
> 
> > Answer 1:
> > <Mike Heins>
>  [story snipped]
> > I think the only thing would be to ... build the initial object
> > at catalog startup time....
> > </Mike Heins>
> 
> Hm, which object would that be in this case, the URL post object? I'm
> not sure I understand how to do this, any pointers?
> 

Looks like the latest rewrite of LWP has taken a turn for the worse
when it comes to Safe.

You could downgrade to an earlier LWP that didn't do that "require every
time at runtime" thing. I really hate that methodology, by the way.

If you add some things to SafeUntrap, you can get away with it inside
of a [perl] tag. I will give a working example so that people can
get an idea of how you can get around this.

SafeUntrap  rand time require caller entereval fileno unpack

UserTag post Order mv_url
UserTag post addAttr
UserTag post Routine <<EOR
use LWP::UserAgent;
sub {
	my ($url, $opt) = @_;
	my $ua = new LWP::UserAgent;
	my $req = new HTTP::Request;
	$req->url($url);
	$req->method('POST');
	delete $opt->{mv_url};
	my @pairs;
	while ( my($k, $v) = each %$opt ) {
	    push @pairs, hexify($k) . '=' . hexify($v);
	}
	$req->content( join('&', @pairs) );
	return $ua->request($req)->as_string;
}
EOR

Put the above in interchange.cfg, then call an appropriate test URL:

<xmp>
[post mv_url="http://sam.heins.net/cgi-bin/env"
	foo="bar with &things to encode"
	baz=buz
]
</xmp>

And then try the embedded Perl version:

<xmp>
[perl]
	my %opt = (
		mv_url => "http://sam.heins.net/cgi-bin/env",
		foo		=> "bar with &things to encode",
		baz		=> 'buz',
	);
	return $Tag->post(\%opt);
[/perl]
</xmp>

Of course you can always make the catalog AllowGlobal, and use
[perl global=1]. But this is Safe-er. 8-)

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

Being against torture ought to be sort of a bipartisan thing.
-- Karl Lehenbauer