httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk-Willem van Gulik <dirk.vangu...@jrc.it>
Subject [patch] ab.c, ab.8
Date Thu, 01 Apr 1999 11:36:01 GMT

On the subject of extening ab to do cookies.

I've been using this hacked version for quite some time. I guess
you could call it well tested. Mainly for Cookies, Accept-Encoding
and Basic AUTH. 

But never thoughd it would be general enough to be usefull. But 
perhaps it is; so I've put the  comments in the ab.8 man page. 
See attached. If I do not hear any loud cries of foul; I'll commit 
it monday or so.

Dw.

Index: ab.c
===================================================================
RCS file: /x3/home/cvs/apache-1.3/src/support/ab.c,v
retrieving revision 1.20
diff -u -c -3 -r1.20 ab.c
*** ab.c	1999/02/19 16:25:35	1.20
--- ab.c	1999/04/01 11:33:30
***************
*** 174,179 ****
--- 174,180 ----
  char *postdata;			/* *buffer containing data from postfile */
  int postlen = 0;		/* length of data to be POSTed */
  char content_type[1024];	/* content type to put in POST header */
+ char cookie[1024], auth[1024], hdrs[4096]; /* XXXX braindead fixed lenght buffers */
  int port = 80;			/* port number */
  
  int use_html = 0;		/* use html in the report */
***************
*** 223,228 ****
--- 224,257 ----
      exit(errno);
  }
  
+ /* -- simple uuencode, lifted from main/util.c which
+  *    needed the pool, so duplicated here with normal 
+  *    malloc. Just for Basic Auth encoding.
+  */
+ static const char basis_64[] = 
+ 	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 
+ 
+ static char * uuencode(char *string) 
+ { 
+ 	int i, len = strlen(string); 
+ 	char *p; 
+ 	char *encoded = (char *) malloc((len+2) / 3 * 4); 
+ 	p = encoded; 
+ 	for (i = 0; i < len; i += 3) { 
+ 		*p++ = basis_64[string[i] >> 2]; 
+ 		*p++ = basis_64[((string[i] & 0x3) << 4) | 
+ 				((int) (string[i + 1] & 0xF0) >> 4) ]; 
+ 		*p++ = basis_64[((string[i + 1] & 0xF) << 2) | 
+ 				((int) (string[i + 2] & 0xC0) >> 6)]; 
+ 		*p++ = basis_64[string[i + 2] & 0x3F]; 
+ 		}; 
+ 	*p-- = '\0'; 
+ 	*p-- = '='; 
+ 	*p-- = '='; 
+ 	return encoded; 
+ 	} 
+ 
+ 
  /* --------------------------------------------------------- */
  
  /* write out request to a connection - assumes we can write
***************
*** 732,760 ****
      if (!posting) {
  	sprintf(request, "GET %s HTTP/1.0\r\n"
  		"User-Agent: ApacheBench/%s\r\n"
! 		"%s"
  		"Host: %s\r\n"
  		"Accept: */*\r\n"
! 		"\r\n",
  		path,
  		VERSION,
  		keepalive ? "Connection: Keep-Alive\r\n" : "",
! 		hostname);
      }
      else {
  	sprintf(request, "POST %s HTTP/1.0\r\n"
  		"User-Agent: ApacheBench/%s\r\n"
! 		"%s"
  		"Host: %s\r\n"
  		"Accept: */*\r\n"
  		"Content-length: %d\r\n"
  		"Content-type: %s\r\n"
  		"\r\n",
  		path,
  		VERSION,
  		keepalive ? "Connection: Keep-Alive\r\n" : "",
  		hostname, postlen,
! 		(content_type[0]) ? content_type : "text/plain");
      }
  
      if (verbosity >= 2)
--- 761,791 ----
      if (!posting) {
  	sprintf(request, "GET %s HTTP/1.0\r\n"
  		"User-Agent: ApacheBench/%s\r\n"
! 		"%s" "%s" "%s"
  		"Host: %s\r\n"
  		"Accept: */*\r\n"
! 		"\r\n" "%s" ,
  		path,
  		VERSION,
  		keepalive ? "Connection: Keep-Alive\r\n" : "",
! 		cookie, auth, hostname,hdrs);
      }
      else {
  	sprintf(request, "POST %s HTTP/1.0\r\n"
  		"User-Agent: ApacheBench/%s\r\n"
! 		"%s" "%s" "%s"	
  		"Host: %s\r\n"
  		"Accept: */*\r\n"
  		"Content-length: %d\r\n"
  		"Content-type: %s\r\n"
+ 		"%s"
  		"\r\n",
  		path,
  		VERSION,
  		keepalive ? "Connection: Keep-Alive\r\n" : "",
+ 		cookie, auth,
  		hostname, postlen,
! 		(content_type[0]) ? content_type : "text/plain",hdrs);
      }
  
      if (verbosity >= 2)
***************
*** 851,856 ****
--- 882,894 ----
      fprintf(stderr, "    -x attributes   String to insert as table attributes\n");
      fprintf(stderr, "    -y attributes   String to insert as tr attributes\n");
      fprintf(stderr, "    -z attributes   String to insert as td or th attributes\n");
+     fprintf(stderr, "    -C attribute	 Add cookie, eg. 'Apache=1234. (repeatable)\n");
+     fprintf(stderr, "    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding:
zop'\n");
+     fprintf(stderr, "                    Inserted after all normal header lines. (repeatable)\n");
+     fprintf(stderr, "    -A attribute    Add Basic WWW Authentication, the attributes\n");
+     fprintf(stderr, "                    are a colon separated username and password.\n");
+     fprintf(stderr, "    -p attribute    Add Basic Proxy Authentication, the attributes\n");
+     fprintf(stderr, "                    are a colon separated username and password.\n");
      fprintf(stderr, "    -V              Print version number and exit\n");
      fprintf(stderr, "    -k              Use HTTP KeepAlive feature\n");
      fprintf(stderr, "    -h              Display usage information (this message)\n");
***************
*** 929,937 ****
      tablestring = "";
      trstring = "";
      tdstring = "bgcolor=white";
! 
      optind = 1;
!     while ((c = getopt(argc, argv, "n:c:t:T:p:v:kVhwx:y:z:")) > 0) {
  	switch (c) {
  	case 'n':
  	    requests = atoi(optarg);
--- 967,975 ----
      tablestring = "";
      trstring = "";
      tdstring = "bgcolor=white";
!     cookie[0]='\0'; auth[0]='\0'; hdrs[0]='\0';
      optind = 1;
!     while ((c = getopt(argc, argv, "n:c:t:T:p:v:kVhwx:y:z:C:H:P:A:")) > 0) {
  	switch (c) {
  	case 'n':
  	    requests = atoi(optarg);
***************
*** 962,967 ****
--- 1000,1030 ----
  	    break;
  	case 'T':
  	    strcpy(content_type, optarg);
+ 	    break;
+ 	case 'C':
+ 	    strncat(cookie, "Cookie: ",sizeof(cookie));
+ 	    strncat(cookie, optarg,sizeof(cookie));
+ 	    strncat(cookie, "\r\n",sizeof(cookie));
+ 	    break;
+ 	case 'A':
+ 	    /* assume username passwd already to be in colon
+ 	     * separated form. Only does basic auth. Use -H for digest.
+ 	     */
+ 	    strncat(cookie, "Authorization: basic ",sizeof(auth));
+ 	    strncat(cookie, uuencode(optarg),sizeof(auth));
+ 	    strncat(cookie, "\r\n",sizeof(auth));
+ 	    break;
+ 	case 'P':
+ 	    /* assume username passwd already to be in colon
+ 	     * separated form.
+ 	     */
+ 	    strncat(cookie, "Proxy-Authorization: basic ",sizeof(auth));
+ 	    strncat(cookie, uuencode(optarg),sizeof(auth));
+ 	    strncat(cookie, "\r\n",sizeof(auth));
+ 	    break;
+ 	case 'H':
+ 	    strncat(cookie, optarg,sizeof(hdrs));
+ 	    strncat(cookie, "\r\n",sizeof(hdrs));
  	    break;
  	case 'V':
  	    copyright();
Index: ab.8
===================================================================
RCS file: /x3/home/cvs/apache-1.3/src/support/ab.8,v
retrieving revision 1.4
diff -u -c -3 -r1.4 ab.8
*** ab.8	1999/02/19 16:25:35	1.4
--- ab.8	1999/04/01 11:33:30
***************
*** 66,71 ****
--- 66,79 ----
  ] [
  .BI \-p " POST file"
  ] [
+ .BI \-A " Authenticate username:password"
+ ] [
+ .BI \-P " Proxy Authenticate username:password"
+ ] [
+ .BI \-H " Custom header"
+ ] [
+ .BI \-C " Cookie name=value"
+ ] [
  .BI \-T " content-type"
  ] [
  .BI \-v " verbosity"
***************
*** 124,129 ****
--- 132,162 ----
  .TP 12
  .BI \-p " POST file"
  File containing data to POST.
+ 
+ .TP 12
+ .BI \-A " Authorization username:password"
+ Supply BASIC Authentification credentials to the server. The username
+ and password are separated by a single ':' and send on the wire uuencoded.
+ The string is send regardless of wether the server needs it; (i.e. has
+ send an 401. Authentifcation needed).
+ 
+ .TP 12
+ .BI \-p " Proxy-Authorization username:password"
+ Supply BASIC Authentification credentials to a proxy en-route. The username
+ and password are separated by a single ':' and send on the wire uuencoded.
+ The string is send regardless of wether the proxy needs it; (i.e. has
+ send an 407 Proxy authentifcation needed).
+ 
+ .TP 12
+ .BI \-C " Cookie name=value"
+ Add a 'Cookie:' line to the request. The argument is typically in the form
+ of a 'name=value' pair. This field is repeatable.
+ 
+ .TP 12
+ .BI \-p " Header string"
+ Postfix extra headers to the request. The argument is typically in the form
+ of a valid header line; containing a colon separated field value pair. (i.e. 
+ 'Accept-Encoding: zip/zop;8bit').
  
  .TP 12
  .BI \-T " content-type"

Mime
View raw message