httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk-Willem van Gulik <di...@webweaving.org>
Subject [patch] possible proxy testing
Date Mon, 05 Apr 1999 17:02:17 GMT

Any serious reasons why not to add proxy capabilities to ab.c. 

Dw.

Index: ab.c
===================================================================
RCS file: /x3/home/cvs/apache-1.3/src/support/ab.c,v
retrieving revision 1.21
diff -u -r1.21 ab.c
--- ab.c	1999/04/05 13:52:21	1.21
+++ ab.c	1999/04/05 17:01:12
@@ -176,8 +176,9 @@
 int tlimit = 0;			/* time limit in cs */
 int keepalive = 0;		/* try and do keepalive connections */
 char servername[1024];		/* name that server reports */
-char hostname[1024];		/* host name */
+char hostname[1024];		/* host name to connect to*/
 char path[1024];		/* path name */
+char full_url[1024];		/* full URL as entered by the user when proxying */
 char postfile[1024];		/* name of file containing post data */
 char *postdata;			/* *buffer containing data from postfile */
 int postlen = 0;		/* length of data to be POSTed */
@@ -187,6 +188,7 @@
 				 * authentification */
      hdrs[4096];		/* optional arbitrary headers */
 int port = 80;			/* port number */
+int proxy = 0;                  /* using proxy ? */
 
 int use_html = 0;		/* use html in the report */
 char *tablestring;
@@ -336,8 +338,8 @@
 
     printf("\r                                                                          
\r");
     printf("Server Software:        %s\n", servername);
-    printf("Server Hostname:        %s\n", hostname);
-    printf("Server Port:            %d\n", port);
+    printf("%s Hostname:        %s\n", (proxy ? "Proxy" : "Server"), hostname);
+    printf("%s Port:            %d\n", (proxy ? "Proxy" : "Server"), port);
     printf("\n");
     printf("Document Path:          %s\n", path);
     printf("Document Length:        %d bytes\n", doclen);
@@ -413,12 +415,12 @@
     printf("<tr %s><th colspan=2 %s>Server Software:</th>"
 	   "<td colspan=2 %s>%s</td></tr>\n",
 	   trstring, tdstring, tdstring, servername);
-    printf("<tr %s><th colspan=2 %s>Server Hostname:</th>"
+    printf("<tr %s><th colspan=2 %s>%s Hostname:</th>"
 	   "<td colspan=2 %s>%s</td></tr>\n",
-	   trstring, tdstring, tdstring, hostname);
-    printf("<tr %s><th colspan=2 %s>Server Port:</th>"
+	   trstring, tdstring, (proxy ? "Proxy" : "Server"), tdstring, hostname);
+    printf("<tr %s><th colspan=2 %s>%s Port:</th>"
 	   "<td colspan=2 %s>%d</td></tr>\n",
-	   trstring, tdstring, tdstring, port);
+	   trstring, tdstring, (proxy ? "Proxy" : "Server"), tdstring, port);
     printf("<tr %s><th colspan=2 %s>Document Path:</th>"
 	   "<td colspan=2 %s>%s</td></tr>\n",
 	   trstring, tdstring, tdstring, path);
@@ -765,12 +767,12 @@
     int i;
 
     if (!use_html) {
-	printf("Benchmarking %s (be patient)...", hostname);
+	printf("Benchmarking %s%s (be patient)...", (proxy ? "PROXY " : ""),hostname);
 	fflush(stdout);
     }
 
     {
-	/* get server information */
+	/* get server or proxy information */
 	struct hostent *he;
 	he = gethostbyname(hostname);
 	if (!he)
@@ -820,7 +822,7 @@
     }
 
     if (verbosity >= 2)
-	printf("INFO: POST header == \n---\n%s\n---\n", request);
+	printf("\nINFO: POST header == \n---\n%s\n---\n", request);
 
     reqlen = strlen(request);
 
@@ -901,7 +903,7 @@
 /* display usage information */
 static void usage(char *progname)
 {
-    fprintf(stderr, "Usage: %s [options] [http://]hostname[:port]/path\n", progname);
+    fprintf(stderr, "Usage: %s [options] [proxyhostname[:port]] [http://]hostname[:port]/path\n",
progname);
     fprintf(stderr, "Options are:\n");
     fprintf(stderr, "    -n requests     Number of requests to perform\n");
     fprintf(stderr, "    -c concurrency  Number of multiple requests to make\n");
@@ -928,16 +930,27 @@
 
 /* ------------------------------------------------------- */
 
-/* split URL into parts */
+/* split URL into parts 
+ * XXX we really should use the parser in main/util_uri.c
+ */
 
 static int parse_url(char *url)
 {
     char *cp;
     char *h;
     char *p = NULL;
+    char * proto = NULL;
+
+    if (proxy) {
+        strcpy(path,url);
+        return 0;
+    }
+	
+    if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0) {
+        strcpy(path,url);
+        url += 7;
+    };
 
-    if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0)
-	url += 7;
     h = url;
     if ((cp = strchr(url, ':')) != NULL) {
 	*cp++ = '\0';
@@ -946,14 +959,37 @@
     }
     if ((cp = strchr(url, '/')) == NULL)
 	return 1;
+
     strcpy(path, cp);
+
     *cp = '\0';
     strcpy(hostname, h);
-    if (p != NULL)
+
+    if ((p != NULL) && (!proxy))
 	port = atoi(p);
+
     return 0;
 }
 
+static int parse_proxy(char *str)
+{
+   char * p = str;
+   str=strsep(&p,":");
+
+   if (p) {
+	port = atoi(p);
+        if (port <=0)
+	   return 1;
+   }
+   else {
+        port = 80;
+   }
+
+   strcpy(hostname,str);
+   proxy = 1;
+   return 0;
+}
+
 /* ------------------------------------------------------- */
 
 /* read data to POST from file, save contents and length */
@@ -1092,6 +1128,11 @@
 	    break;
 	}
     }
+    if ((optind == argc - 2)&&(parse_proxy(argv[optind++]))) { 
+	fprintf(stderr, "%s: invalid proxy\n", argv[0]);
+	usage(argv[0]);
+    }
+
     if (optind != argc - 1) {
 	fprintf(stderr, "%s: wrong number of arguments\n", argv[0]);
 	usage(argv[0]);
Index: ab.8
===================================================================
RCS file: /x3/home/cvs/apache-1.3/src/support/ab.8,v
retrieving revision 1.5
diff -u -r1.5 ab.8
--- ab.8	1999/04/05 13:52:20	1.5
+++ ab.8	1999/04/05 17:01:12
@@ -69,8 +69,6 @@
 ] [
 .BI \-A " Authenticate username:password"
 ] [
-.BI \-P " Proxy Authenticate username:password"
-] [
 .BI \-H " Custom header"
 ] [
 .BI \-C " Cookie name=value"
@@ -78,16 +76,12 @@
 .BI \-T " content-type"
 ] [
 .BI \-v " verbosity"
-]
 ] [
 .BI \-w " output HTML"
-]
 ] [
 .BI \-x " <table> attributes"
-]
 ] [
 .BI \-y " <tr> attributes"
-]
 ] [
 .BI \-z " <td> attributes"
 ]
@@ -95,6 +89,40 @@
 
 .B ab
 [
+.B \-k
+] [
+.BI \-n " requests"
+] [
+.BI \-t " timelimit"
+] [
+.BI \-c " concurrency"
+] [
+.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"
+] [ 
+.BI \-w " output HTML"
+] [ 
+.BI \-x " <table> attributes"
+] [    
+.BI \-y " <tr> attributes"
+] [    
+.BI \-z " <td> attributes"
+]
+.I proxyhost[:port] url
+
+.B ab
+[
 .B \-V
 ] [
 .B \-h 
@@ -107,6 +135,11 @@
 current Apache installation.  This especially shows you how much requests per
 time your Apache installation is capable to serve. 
 .PP
+When connecting directly to a server, the target can be specified eiter as a
+valid HTTP url, i.e something which begins with 'http://'. or as a plain 
+hostname:port/path. When specifying a proxyhost as an intermediate you
+must specify a full URL.
+.PP
 .SH OPTIONS
 .TP 12
 .B \-k 
@@ -146,7 +179,8 @@
 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).
+send an 407 Proxy authentifcation needed). Only makes sense when using the
+second form of the command; i.e. when actually going through a proxy.
 
 .TP 12
 .BI \-C " Cookie name=value"
@@ -192,6 +226,23 @@
 .B \-h 
 Display usage information.
 .PD
+
+.SH EXAMPLES
+
+Fetching a page a hundred times (both examples are equivalent):
+.P
+.B	ab -n 100 http://kim.ispra.webweaving.org/index.html
+.P
+.B	ab -n 100 kim.ispra.webweaving.org:80/index.html
+.P
+Fetching a page through a proxy:
+.P
+.B	ab proxy.webweaving.org:88 http://prometeus.org
+.P
+Getting a very verbose and complete trace of what happens on the wire:
+.P
+.B	ab -n 1 -v 5 http://kim.ispra.webweaving.org/index.html
+.P
 .SH BUGS
 There are various statically declared buffers of fixed length. Combined
 with the lazy parsing of the command line arguments, the response headers
@@ -204,7 +255,9 @@
 which might indicate a performance problem; i.e. you would measure the
 .BR ab
 performance rather than the server's.
-
+.P
+We propably should parse the URL properly. Especially when passing it to
+a proxy. 
 .SH SEE ALSO
 .BR httpd(8)
 .


Mime
View raw message