From: Jim Jagielski Date: Tue, 1 May 2007 13:12:59 +0000 (+0000) Subject: Backports: X-Git-Tag: 2.2.5~275 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6833e744c6bdbb0d170d5d3119e0b5a3591f655a;p=thirdparty%2Fapache%2Fhttpd.git Backports: Correct behavior of HTTP request headers sent by ab in presence of -H command- line overrides. Previously, ab would concatenate a supplied -H User-Agent: header to the existing one, and send duplicate headers if either -H Host: or -H Accept: were specified on the command line. Now, the default headers are not sent if they are overridden using the -H command-line flag. Submitted by: Arvind Srinivasan arvind.srinivasan sun.com Reviewed by: sctemme PR: 31268, 26554 The apr_port_t type is unsigned, but ab was using a signed format code in its reports. PR 42070. Submitted by Takashi Sato serai lans-tv.com, reviewed by sctemme. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@534057 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index eb9232b2ff4..d5e45c9488b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,15 @@ -*- coding: utf-8 -*- Changes with Apache 2.2.5 - * mod_ldap: Remove the hardcoded size limit parameter for + *) ab.c: Correct behavior of HTTP request headers sent by ab + in presence of -H command-line overrides. PR 31268, 26554. + [Arvind Srinivasan ] + + *) ab.c: The apr_port_t type is unsigned, but ab was using a + signed format code in its reports. PR 42070. + [Takashi Sato ] + + *) mod_ldap: Remove the hardcoded size limit parameter for ldap_search_ext_s and replace it with an APR_ defined value that is set according to the LDAP SDK being used. [David Jones ] diff --git a/support/ab.c b/support/ab.c index 24760df99b3..7efff3149cd 100644 --- a/support/ab.c +++ b/support/ab.c @@ -284,6 +284,11 @@ char url[1024]; char * fullurl, * colonhost; int isproxy = 0; apr_interval_time_t aprtimeout = apr_time_from_sec(30); /* timeout value */ + +/* overrides for ab-generated common headers */ +int opt_host = 0; /* was an optional "Host:" header specified? */ +int opt_useragent = 0; /* was an optional "User-Agent:" header specified? */ +int opt_accept = 0; /* was an optional "Accept:" header specified? */ /* * XXX - this is now a per read/write transact type of value */ @@ -731,7 +736,7 @@ static void output_results(void) printf("\n\n"); printf("Server Software: %s\n", servername); printf("Server Hostname: %s\n", hostname); - printf("Server Port: %hd\n", port); + printf("Server Port: %hu\n", port); #ifdef USE_SSL if (is_ssl && ssl_info) { printf("SSL/TLS Protocol: %s\n", ssl_info); @@ -990,7 +995,7 @@ static void output_html_results(void) "%s\n", trstring, tdstring, tdstring, hostname); printf("Server Port:" - "%hd\n", + "%hu\n", trstring, tdstring, tdstring, port); printf("Document Path:" "%s\n", @@ -1512,37 +1517,54 @@ static void test(void) apr_err("apr_pollset_create failed", status); } + /* add default headers if necessary */ + if (!opt_host) { + /* Host: header not overridden, add default value to hdrs */ + hdrs = apr_pstrcat(cntxt, hdrs, "Host: ", host_field, colonhost, "\r\n", NULL); + } + else { + /* Header overridden, no need to add, as it is already in hdrs */ + } + + if (!opt_useragent) { + /* User-Agent: header not overridden, add default value to hdrs */ + hdrs = apr_pstrcat(cntxt, hdrs, "User-Agent: ApacheBench/", AP_AB_BASEREVISION, "\r\n", NULL); + } + else { + /* Header overridden, no need to add, as it is already in hdrs */ + } + + if (!opt_accept) { + /* Accept: header not overridden, add default value to hdrs */ + hdrs = apr_pstrcat(cntxt, hdrs, "Accept: */*\r\n", NULL); + } + else { + /* Header overridden, no need to add, as it is already in hdrs */ + } + /* setup request */ if (posting <= 0) { snprintf_res = apr_snprintf(request, sizeof(_request), "%s %s HTTP/1.0\r\n" - "User-Agent: ApacheBench/%s\r\n" "%s" "%s" "%s" - "Host: %s%s\r\n" - "Accept: */*\r\n" "%s" "\r\n", (posting == 0) ? "GET" : "HEAD", (isproxy) ? fullurl : path, - AP_AB_BASEREVISION, keepalive ? "Connection: Keep-Alive\r\n" : "", - cookie, auth, host_field, colonhost, hdrs); + cookie, auth, hdrs); } else { snprintf_res = apr_snprintf(request, sizeof(_request), "POST %s HTTP/1.0\r\n" - "User-Agent: ApacheBench/%s\r\n" "%s" "%s" "%s" - "Host: %s%s\r\n" - "Accept: */*\r\n" "Content-length: %" APR_SIZE_T_FMT "\r\n" "Content-type: %s\r\n" "%s" "\r\n", (isproxy) ? fullurl : path, - AP_AB_BASEREVISION, keepalive ? "Connection: Keep-Alive\r\n" : "", cookie, auth, - host_field, colonhost, postlen, + postlen, (content_type[0]) ? content_type : "text/plain", hdrs); } if (snprintf_res >= sizeof(_request)) { @@ -2035,6 +2057,16 @@ int main(int argc, const char * const argv[]) break; case 'H': hdrs = apr_pstrcat(cntxt, hdrs, optarg, "\r\n", NULL); + /* + * allow override of some of the common headers that ab adds + */ + if (strncasecmp(optarg, "Host:", 5) == 0) { + opt_host = 1; + } else if (strncasecmp(optarg, "Accept:", 7) == 0) { + opt_accept = 1; + } else if (strncasecmp(optarg, "User-Agent:", 11) == 0) { + opt_useragent = 1; + } break; case 'w': use_html = 1;