ApacheBench
view release on metacpan or search on metacpan
implement strnstr() function since glibc does not have it (in src/apachebench/util.c)
reorganize all C code into logically separated libraries: src/apachebench/*.[ch]
remove includes to apache header files ap.h, ap_config.h, ap_ctype.h, os.h, os-win32.h, etc;
now we rely completely on system includes
=item 0.70 - Nov 14, 2010
add support for dynamic cookie management within runs (emulate what browsers do):
- read "Set-Cookie:" headers from each response and append corresponding "Cookie:"
headers to subsequent requests later in same run
- feature turned on by default, but can be disabled by run
new method $b->num_runs() to return the number of runs currently configured
clean up XS code some more, renaming variables to be more sensible
get rid of Term::ReadKey based test requiring user input from t/test3_execute.t,
to stop annoying e-mail from cpantesters
lib/HTTPD/Bench/ApacheBench.pm view on Meta::CPAN
$b->concurrency(5);
$b->priority("run_priority");
# add HTTP request sequences (aka: runs)
my $run1 = HTTPD::Bench::ApacheBench::Run->new
({ urls => ["http://localhost/one", "http://localhost/two"] });
$b->add_run($run1);
my $run2 = HTTPD::Bench::ApacheBench::Run->new
({ urls => ["http://localhost/three", "http://localhost/four"],
cookies => ["Login_Cookie=b3dcc9bac34b7e60;"],
# note: manual cookies no longer necessary due to use_auto_cookies (enabled by default)
order => "depth_first",
repeat => 10,
memory => 2 });
$b->add_run($run2);
my $run3 = HTTPD::Bench::ApacheBench::Run->new
({ urls => ["http://localhost/five", "http://localhost/six"],
memory => 3,
postdata => [
lib/HTTPD/Bench/ApacheBench.pm view on Meta::CPAN
=item $run->repeat( $n )
Number of times to repeat this request sequence.
(default: B<1>, or whatever is specified in global configuration)
=item $run->use_auto_cookies( 0|1 )
Controls whether to enable dynamic setting of cookies based on previous
response headers in this run. If set, will parse the Set-Cookie: headers
in each response in the run, and set the corresponding Cookie: headers in
all subsequent requests in this run. (basically a crude, but fast emulation
of a browser's cookie handling mechanism) The cookies are cumulative for
each iteration of the run, so they will accumulate with each request/response
pair until the next iteration, when they get reset.
(default: B<1>)
=item $run->cookies( \@cookies )
Set any extra HTTP Cookie: headers for each B<repetition> of this run.
Length of @cookies should equal $n (whatever you set $run->repeat to).
If this option is omitted, only auto-set cookies will be sent in
requests for this run.
If you need to set different cookies within a single URL sequence, use
the request_headers() method.
Note: this is somewhat obsolete now that there is support for dynamic
cookies, but is kept for backwards compatibility and in case you want to
add your own "static" cookies.
src/ApacheBench.xs view on Meta::CPAN
/*
** HISTORY:
** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
** with input from Mike Belshe <mbelshe@netscape.com> and
** Michael Campanella <campanella@stevms.enet.dec.com>
** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
**
** - CODE FORK: added Perl XS interface and is now released on CPAN as
** HTTPD::Bench::ApacheBench, September 2000
** - merged code from Apache 1.3.22 ab, October-November 2001
** - various refactors, rewrites, and improvements; see Changes
**
*/
/*
* BUGS:
src/apachebench/http_util.c view on Meta::CPAN
strcat(registry->path[i], tok2);
} else
strcpy(registry->path[i], tok2);
return 0;
}
/* --------------------------------------------------------- */
/* extract cookies from response_data (Set-Cookie: headers) and save to auto_cookies */
static void
allocate_auto_cookie_memory(struct global * registry, struct connection * c) {
#ifdef AB_DEBUG
printf("AB_DEBUG: start of allocate_auto_cookie_memory(): run %d, thread %d\n", c->run, c->thread);
#endif
if (registry->auto_cookies[c->run] == NULL) {
registry->auto_cookies[c->run] = (char **) calloc(registry->repeats[c->run], sizeof(char *));
#ifdef AB_DEBUG
src/apachebench/http_util.c view on Meta::CPAN
return;
allocate_auto_cookie_memory(registry, c);
#ifdef AB_DEBUG
printf("AB_DEBUG: extract_cookies_from_response() - stage 1; run %d, thread %d\n", c->run, c->thread);
#endif
if (! c->response_headers) return;
set_cookie_hdr = strstr(c->response_headers, "\r\nSet-Cookie: ");
while (set_cookie_hdr) {
remove_existing_cookie_from_auto_cookies(registry, c, set_cookie_hdr);
#ifdef AB_DEBUG
printf("AB_DEBUG: extract_cookies_from_response() - stage 2.1; run %d, thread %d, postdata[%d] = %s\n", c->run, c->thread, c->url, registry->postdata[c->url]);
#endif
eoh = strstr(set_cookie_hdr+2, "\r\n");
if (! strnstr(set_cookie_hdr, "=; Expires=", eoh - set_cookie_hdr)) // hack: do not set expired headers
// drop the "Set-" from beginning to just append "Cookie: ....\r\n"
strncat(registry->auto_cookies[c->run][c->thread], set_cookie_hdr + 6, eoh - set_cookie_hdr - 4);
#ifdef AB_DEBUG
printf("AB_DEBUG: extract_cookies_from_response() - stage 2.2; run %d, thread %d, auto_cookies[%d][%d] = %s\n", c->run, c->thread, c->run, c->url, registry->auto_cookies[c->run][c->thread]);
#endif
set_cookie_hdr = strstr(set_cookie_hdr+1, "\r\nSet-Cookie: ");
}
}
/* remove existing cookies from registry->auto_cookies[..][..] which will be set again by extract_cookies_from_response() */
static void
remove_existing_cookie_from_auto_cookies(struct global * registry, struct connection * c, char * set_cookie_hdr) {
char *existing_cookie, *end_of_existing_cookie, *cookie_name, *new_auto_cookies, *eoh;
#ifdef AB_DEBUG
printf("AB_DEBUG: start of remove_existing_cookie_from_auto_cookies(), postdata[%d] = %s\n", c->url, registry->postdata[c->url]);
#endif
// first need to find the name of cookie on current "Set-Cookie: " header line
cookie_name = (char *) calloc(CBUFFSIZE, sizeof(char));
strcat(cookie_name, "Cookie: ");
eoh = strstr(set_cookie_hdr+14, "\r\n");
strncat(cookie_name, set_cookie_hdr+14, strnstr(set_cookie_hdr+14, "=", eoh-(set_cookie_hdr+14)) - (set_cookie_hdr+14));
#ifdef AB_DEBUG
printf("AB_DEBUG: remove_existing_cookie_from_auto_cookies() - stage 1\n");
#endif
existing_cookie = strstr(registry->auto_cookies[c->run][c->thread], cookie_name);
#ifdef AB_DEBUG
src/apachebench/socket_io.c view on Meta::CPAN
ctype);
}
#ifdef AB_DEBUG
printf("AB_DEBUG: reset_request() - stage 2\n");
#endif
if (registry->keepalive[i])
strcat(c->request_headers, "Connection: Keep-Alive\r\n");
if (registry->cookie[c->run]) {
strcat(c->request_headers, "Cookie: ");
strcat(c->request_headers, registry->cookie[c->run]);
strcat(c->request_headers, "\r\n");
}
#ifdef AB_DEBUG
printf("AB_DEBUG: reset_request() - stage 2.1: c->run %d; c->thread %d\n", c->run, c->thread);
#endif
allocate_auto_cookie_memory(registry, c);
( run in 0.412 second using v1.01-cache-2.11-cpan-e9199f4ba4c )