[interchange-cvs] interchange - heins modified
code/UserTag/get_url.tag
interchange-cvs at icdevgroup.org
interchange-cvs at icdevgroup.org
Tue Jul 13 12:47:52 EDT 2004
User: heins
Date: 2004-07-13 16:47:51 GMT
Modified: code/UserTag get_url.tag
Log:
* Add Jonathan Clark's suggested timeout set, with ability to
read time strings like timeout="1 minute".
* Add standard interhange form parameter, i.e. don't require urlencode
of content for post.
[get-url
method=POST
form=|
foo=bar
buz=baz
boo=The red's the thing.
|]
Still accepts content="foo=bar&buz=baz&boo=the%20big%20red%27s%20the%20one".
* Handle lower-case method names.
* Don't set content() unless a POST or PUT.
Revision Changes Path
1.6 +26 -8 interchange/code/UserTag/get_url.tag
rev 1.6, prev_rev 1.5
Index: get_url.tag
===================================================================
RCS file: /var/cvs/interchange/code/UserTag/get_url.tag,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- get_url.tag 7 Jan 2004 05:13:50 -0000 1.5
+++ get_url.tag 13 Jul 2004 16:47:51 -0000 1.6
@@ -48,19 +48,37 @@
}
else { $method = "GET"; }
- if($opt->{useragent} ) {
- $ua->agent($opt->{useragent});
- }
+ $method = uc $method;
- my $req = HTTP::Request->new($method, $url);
+ if($opt->{timeout}) {
+ my $to = Vend::Config::time_to_seconds($opt->{timeout});
+ $ua->timeout($to);
+ }
- $req->content_type('application/x-www-form-urlencoded');
- if($opt->{content_type}) {
- $req->content_type($opt->{content_type});
+ if($opt->{useragent} ) {
+ $ua->agent($opt->{useragent});
}
+ if($opt->{form}) {
+ $opt->{content} = Vend::Interpolate::escape_form($opt->{form});
+ }
+
+ my $do_content;
+
if(($opt->{content}) && ("PUT POST" =~ /$method/)) {
- $req->content($opt->{content});
+ $opt->{content_type} ||= 'application/x-www-form-urlencoded';
+ $do_content = 1;
+ }
+ elsif($opt->{content}) {
+ $url .= $opt->{url} =~ /\?/ ? '&' : '?';
+ $url .= $opt->{content};
+ }
+
+ my $req = HTTP::Request->new($method, $url);
+
+ if($do_content) {
+ $req->content_type($opt->{content_type});
+ $req->content($opt->{content});
}
if($opt->{authuser} && $opt->{authpass}) {
More information about the interchange-cvs
mailing list