Update of /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest/Plugin
In directory usw-pr-cvs1:/tmp/cvs-serv30499/lib/HTTP/WebTest/Plugin
Modified Files:
Cookies.pm
Log Message:
New cookie spec format
Index: Cookies.pm
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest/Plugin/Cookies.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Cookies.pm 21 Jun 2002 06:48:16 -0000 1.5
--- Cookies.pm 2 Jul 2002 22:45:08 -0000 1.6
***************
*** 72,95 ****
Synonym to C<cookies>.
=head2 cookies
! Specifies a cookie(s) to send to the web server.
Each cookie is specified by following list:
! ( version
! name
! value
! path
! domain
! port
! path_spec
! secure
! maxage
! discard
! name1
! value1
! name2
! value2
...
)
--- 72,255 ----
Synonym to C<cookies>.
+ It is deprecated parameter and may be removed in future versions of
+ L<HTTP::WebTest|HTTP::WebTest>.
+
=head2 cookies
! This is a list parameter that specifies cookies to send to the web
! server:
!
! cookies = ( cookie1_spec
! cookie2_spec
! ...
! cookieN_spec )
!
! Currently there are two ways to specify a cookie.
!
! =over 4
!
! =item * Named style
!
! A cookie is specified by a set of C<param =E<gt> value> pairs:
!
! (
! param => value
! ...
! )
!
! List of all supported C<param =E<gt> value> pairs:
!
! =over 4
!
! =item version => VERSION
!
! Version number of cookie spec to use, usually 0.
!
! =item name => NAME (REQUIRED)
!
! Name of cookie. Cannot begin with a $ character.
!
! =item value => VALUE (REQUIRED)
!
! Value of cookie.
!
! =item path => PATH (REQUIRED)
!
! URL path name for which this cookie applies. Must begin with a /
! character. See also path_spec.
!
! =item domain => DOMAIN (REQUIRED)
!
! Domain for which cookie is valid. Must either contain two periods or
! be equal to C<.local>.
!
! =item port => PORT
!
! List of allowed port numbers that the cookie may be returned to. If
! not specified, cookie can be returned to any port. Must be specified
! using the format C<N> or C<N, N, ..., N> where N is one or more
! digits.
!
! =item path_spec => PATH_SPEC
!
! Ignored if version is less than 1. Option to ignore the value of
! path. Default value is 0.
!
! =over 4
!
! =item * 1
!
! Use the value of path.
!
! =item * 0
!
! Ignore the specified value of path.
!
! =back
!
! =item secure => SECURE
!
! Option to require secure protocols for cookie transmission. Default
! value is 0.
!
! =over 4
!
! =item * 1
!
! Use only secure protocols to transmit this cookie.
!
! =item * 0
!
! Secure protocols are not required for transmission.
!
! =back
!
! =item maxage => MAXAGE
!
! Number of seconds until cookie expires.
!
! =item discard => DISCARD
!
! Option to discard cookie when the program finishes. Default is 0.
! (The cookie will be discarded regardless of the value of this
! element.)
!
! =over 4
!
! =item * 1
!
! Discard cookie when the program finishes.
!
! =item * 0
!
! Don't discard cookie.
!
! =back
!
! =item rest => NAME_VALUE_LIST
!
! Defines additional cookie attributes.
!
! Zero, one or several name/value pairs may be specified. The name
! parameters are words such as Comment or CommentURL and the value
! parameters are strings that may contain embedded blanks.
!
! =back
!
! Example (wtscript file):
!
! cookies = ( ( name => Cookie1
! value => cookie value )
!
! ( name => Cookie2
! value => cookie value
! path => /
! domain => .company.com ) )
!
! ( name => Cookie2
! value => cookie value
! rest => ( Comment => this is a comment ) )
!
! Example (Perl script):
!
! my $tests = [
! ...
! {
! test_name => 'cookie',
! cookies => [ [
! name => 'Cookie1',
! value => 'Value',
! ],
! [
! name => 'Cookie2',
! value => 'Value',
! path => '/',
! ] ],
! ...
! }
! ...
! ]
!
! =item * Row list style
!
! This style of cookie specification is deprecated and may be removed in
! future versions of L<HTTP::WebTest|HTTP::WebTest>.
Each cookie is specified by following list:
! ( VERSION
! NAME
! VALUE
! PATH
! DOMAIN
! PORT
! PATH_SPEC
! SECURE
! MAXAGE
! DISCARD
! NAME1
! VALUE1
! NAME2
! VALUE2
...
)
***************
*** 101,127 ****
=over 4
! =item * version (REQUIRED)
Version number of cookie spec to use, usually 0.
! =item * name (REQUIRED)
Name of cookie. Cannot begin with a $ character.
! =item * value (REQUIRED)
Value of cookie.
! =item * path (REQUIRED)
URL path name for which this cookie applies. Must begin with a /
character. See also path_spec.
! =item * domain (REQUIRED)
! Domain for which cookie is valid. (REQUIRED). Should begin with a
! period. Must either contain two periods or be equal to C<.local>.
! =item * port
List of allowed port numbers that the cookie may be returned to. If
--- 261,287 ----
=over 4
! =item * VERSION (REQUIRED)
Version number of cookie spec to use, usually 0.
! =item * NAME (REQUIRED)
Name of cookie. Cannot begin with a $ character.
! =item * VALUE (REQUIRED)
Value of cookie.
! =item * PATH (REQUIRED)
URL path name for which this cookie applies. Must begin with a /
character. See also path_spec.
! =item * DOMAIN (REQUIRED)
! Domain for which cookie is valid. Must either contain two periods or
! be equal to C<.local>.
! =item * PORT
List of allowed port numbers that the cookie may be returned to. If
***************
*** 130,134 ****
digits.
! =item * path_spec
Ignored if version is less than 1. Option to ignore the value of
--- 290,294 ----
digits.
! =item * PATH_SPEC
Ignored if version is less than 1. Option to ignore the value of
***************
*** 147,151 ****
=back
! =item * secure
Option to require secure protocols for cookie transmission. Default
--- 307,311 ----
=back
! =item * SECURE
Option to require secure protocols for cookie transmission. Default
***************
*** 164,172 ****
=back
! =item * maxage
Number of seconds until cookie expires.
! =item * discard
Option to discard cookie when the program finishes. Default is 0.
--- 324,332 ----
=back
! =item * MAXAGE
Number of seconds until cookie expires.
! =item * DISCARD
Option to discard cookie when the program finishes. Default is 0.
***************
*** 196,225 ****
An example cookie would look like:
! ( 0
! WebTest cookie #1
! expires&2592000&type&consumer
! /
! .mycompany.com
! ''
! 0
! 0
! 200
! 1
! )
!
! See RFC 2965 for details (ftp://ftp.isi.edu/in-notes/rfc2965.txt).
!
! =head3 Usage in wtscript files
!
! You may specify multiple cookies within each test block by specifying
! multiple instances of the C<cookies> parameter.
!
! =head3 Usage in Perl scripts
! Use an arrayref of arrayrefs containing cookies to pass with the HTTP
! request.
! Each array must have at least 5 elements; if the number of elements is
! over 10 it must have an even number of elements.
=cut
--- 356,374 ----
An example cookie would look like:
! cookies = ( ( 0
! WebTest cookie #1
! cookie value
! /
! .mycompany.com
! ''
! 0
! 0
! 200
! 1
! ) )
! =back
! See RFC 2965 for details (ftp://ftp.isi.edu/in-notes/rfc2965.txt).
=cut
***************
*** 241,246 ****
my $accept_cookies = $self->yesno_test_param('accept_cookies', 1);
! my $send_cookies = $self->yesno_test_param('send_cookies', 1);
! my $cookies = $self->test_param('cookies');
$cookies ||= $self->test_param('cookie'); # alias for parameter
$cookies = $self->transform_cookies($cookies) if defined $cookies;
--- 390,396 ----
my $accept_cookies = $self->yesno_test_param('accept_cookies', 1);
! my $send_cookies = $self->yesno_test_param('send_cookies', 1);
! my $cookies = $self->test_param('cookies');
!
$cookies ||= $self->test_param('cookie'); # alias for parameter
$cookies = $self->transform_cookies($cookies) if defined $cookies;
***************
*** 275,301 ****
my $cookies = shift;
! # check if $cookies is list of list
unless(ref($$cookies[0]) eq 'ARRAY') {
return $self->transform_cookies([ $cookies ]);
}
! my @new_cookies = ();
for my $cookie (@$cookies) {
! # make copy of cookie (missing fields are set to undef)
! my @new_cookie = @$cookie[0 .. NCOOKIE_REFORMAT - 1];
! # replace '' with undef
! @new_cookie = map +(defined($_) and $_ eq '') ? (undef) : $_,
! @new_cookie;
! # collect all additional attributes (name, value pairs)
! my @extra = @$cookie[ NCOOKIE_REFORMAT .. @$cookie - 1];
! push @new_cookie, { @extra };
! push @new_cookies, \@new_cookie;
}
! return \@new_cookies;
}
--- 425,506 ----
my $cookies = shift;
! # check if $cookies is array of arrays
unless(ref($$cookies[0]) eq 'ARRAY') {
return $self->transform_cookies([ $cookies ]);
}
! my @cookies = ();
for my $cookie (@$cookies) {
! # simple heuristic to distinguish deprecated format from new:
! # in new format $cookie->[0] cannot be a number while it is
! # expected for deprecated
! if($cookie->[0] =~ /^ \d* $/x) {
! $cookie = $self->transform_cookie_deprecated($cookie);
! } else {
! $cookie = $self->transform_cookie($cookie);
! }
! die "HTTP::WebTest: missing cookie name"
! unless defined $cookie->[1];
! die "HTTP::WebTest: missing cookie path"
! unless defined $cookie->[3];
! die "HTTP::WebTest: missing cookie domain"
! unless defined $cookie->[4];
! push @cookies, $cookie;
! }
! return \@cookies;
! }
!
! # transform cookie to the canonic representation (a list expected by
! # HTTP::Cookie::set_cookie)
! sub transform_cookie {
! my $self = shift;
! my $cookie = shift;
!
! my %fields = ( version => 0,
! name => 1,
! value => 2,
! path => 3,
! domain => 4,
! port => 5,
! path_spec => 6,
! secure => 7,
! expires => 8,
! discard => 9,
! rest => 10 );
!
! my @canonic = ();
! my %cookie = @$cookie;
! while(my($field, $value) = each %cookie) {
! $canonic[$fields{$field}] = $value;
}
! # convert rest part from array ref to hash ref
! $canonic[10] = { @{$canonic[10]} } if defined $canonic[10];
!
! return \@canonic;
! }
!
! # transform cookie specified using deprecated format to the canonic
! # representation (a list expected by HTTP::Cookie::set_cookie)
! sub transform_cookie_deprecated {
! my $self = shift;
! my $cookie = shift;
!
! # make a copy of cookie (missing fields are set to undef)
! my @canonic = @$cookie[0 .. NCOOKIE_REFORMAT - 1];
!
! # replace '' with undef
! @canonic = map +(defined($_) and $_ eq '') ? (undef) : $_,
! @canonic;
!
! # collect all additional attributes (name, value pairs)
! my @extra = @$cookie[ NCOOKIE_REFORMAT .. @$cookie - 1];
! push @canonic, { @extra };
!
! return \@canonic;
}
|