httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Barnes <jbarnes...@yahoo.com>
Subject Re: ab
Date Tue, 18 Aug 2009 12:22:29 GMT
Here is the svn diff for ab to implement PUT requests. I also modified the ab man page, but
I don't know where to check it out. I can provide the updated man page in its entirety or
someone could point me to the svn server for it and I can send a diff. Or ?

Best regards,
Jeff Barnes

Index: ab.c
===================================================================
--- ab.c	(revision 18)
+++ ab.c	(working copy)
@@ -807,8 +807,10 @@
     if (keepalive)
         printf("Keep-Alive requests:    %d\n", doneka);
     printf("Total transferred:      %" APR_INT64_T_FMT " bytes\n", totalread);
-    if (posting > 0)
+    if (posting == 1)
         printf("Total POSTed:           %" APR_INT64_T_FMT "\n", totalposted);
+    else if (posting == 2)
+        printf("Total PUT:              %" APR_INT64_T_FMT "\n", totalposted);
     printf("HTML transferred:       %" APR_INT64_T_FMT " bytes\n", totalbread);
 
     /* avoid divide by zero */
@@ -1092,10 +1094,14 @@
     printf("<tr %s><th colspan=2 %s>Total transferred:</th>"
        "<td colspan=2 %s>%" APR_INT64_T_FMT " bytes</td></tr>\n",
        trstring, tdstring, tdstring, totalread);
-    if (posting > 0)
+    if (posting == 1)
         printf("<tr %s><th colspan=2 %s>Total POSTed:</th>"
            "<td colspan=2 %s>%" APR_INT64_T_FMT "</td></tr>\n",
            trstring, tdstring, tdstring, totalposted);
+    else if (posting == 2)
+        printf("<tr %s><th colspan=2 %s>Total PUT:</th>"
+           "<td colspan=2 %s>%" APR_INT64_T_FMT "</td></tr>\n",
+           trstring, tdstring, tdstring, totalposted);
     printf("<tr %s><th colspan=2 %s>HTML transferred:</th>"
        "<td colspan=2 %s>%" APR_INT64_T_FMT " bytes</td></tr>\n",
        trstring, tdstring, tdstring, totalbread);
@@ -1637,7 +1643,7 @@
             keepalive ? "Connection: Keep-Alive\r\n" : "",
             cookie, auth, hdrs);
     }
-    else {
+    else if (posting == 1) {
         snprintf_res = apr_snprintf(request,  sizeof(_request),
             "POST %s HTTP/1.0\r\n"
             "%s" "%s" "%s"
@@ -1651,6 +1657,21 @@
             postlen,
             (content_type[0]) ? content_type : "text/plain", hdrs);
     }
+    else {
+        snprintf_res = apr_snprintf(request,  sizeof(_request),
+            "PUT %s HTTP/1.0\r\n"
+            "%s" "%s" "%s"
+            "Content-length: %" APR_SIZE_T_FMT "\r\n"
+            "Content-type: %s\r\n"
+            "%s"
+            "\r\n",
+            (isproxy) ? fullurl : path,
+            keepalive ? "Connection: Keep-Alive\r\n" : "",
+            cookie, auth,
+            postlen,
+            (content_type[0]) ? content_type : "text/plain", hdrs);
+    }
+
     if (snprintf_res >= sizeof(_request)) {
         err("Request too long\n");
     }
@@ -1663,7 +1684,7 @@
     /*
      * Combine headers and (optional) post file into one contineous buffer
      */
-    if (posting == 1) {
+    if (posting >= 1) {
         char *buff = malloc(postlen + reqlen + 1);
         if (!buff) {
             fprintf(stderr, "error creating request buffer: out of memory\n");
@@ -1852,6 +1873,7 @@
     fprintf(stderr, "    -t timelimit    Seconds to max. wait for responses\n");
     fprintf(stderr, "    -b windowsize   Size of TCP send/receive buffer, in bytes\n");
     fprintf(stderr, "    -p postfile     File containing data to POST. Remember also to set
-T\n");
+    fprintf(stderr, "    -u postfile     File containing data to PUT. Remember also to set
-T\n");
     fprintf(stderr, "    -T content-type Content-type header for POSTing, eg.\n");
     fprintf(stderr, "                    'application/x-www-form-urlencoded'\n");
     fprintf(stderr, "                    Default is 'text/plain'\n");
@@ -1967,26 +1989,26 @@
 
     rv = apr_file_open(&postfd, pfile, APR_READ, APR_OS_DEFAULT, cntxt);
     if (rv != APR_SUCCESS) {
-        fprintf(stderr, "ab: Could not open POST data file (%s): %s\n", pfile,
+        fprintf(stderr, "ab: Could not open POST/PUT data file (%s): %s\n", pfile,
                 apr_strerror(rv, errmsg, sizeof errmsg));
         return rv;
     }
 
     rv = apr_file_info_get(&finfo, APR_FINFO_NORM, postfd);
     if (rv != APR_SUCCESS) {
-        fprintf(stderr, "ab: Could not stat POST data file (%s): %s\n", pfile,
+        fprintf(stderr, "ab: Could not stat POST/PUT data file (%s): %s\n", pfile,
                 apr_strerror(rv, errmsg, sizeof errmsg));
         return rv;
     }
     postlen = (apr_size_t)finfo.size;
     postdata = malloc(postlen);
     if (!postdata) {
-        fprintf(stderr, "ab: Could not allocate POST data buffer\n");
+        fprintf(stderr, "ab: Could not allocate POST/PUT data buffer\n");
         return APR_ENOMEM;
     }
     rv = apr_file_read_full(postfd, postdata, postlen, NULL);
     if (rv != APR_SUCCESS) {
-        fprintf(stderr, "ab: Could not read POST data file: %s\n",
+        fprintf(stderr, "ab: Could not read POST/PUT data file: %s\n",
                 apr_strerror(rv, errmsg, sizeof errmsg));
         return rv;
     }
@@ -2045,7 +2067,7 @@
 #endif
 
     apr_getopt_init(&opt, cntxt, argc, argv);
-    while ((status = apr_getopt(opt, "n:c:t:b:T:p:v:rkVhwix:y:z:C:H:P:A:g:X:de:Sq"
+    while ((status = apr_getopt(opt, "n:c:t:b:T:p:u:v:rkVhwix:y:z:C:H:P:A:g:X:de:Sq"
 #ifdef USE_SSL
             "Z:f:"
 #endif
@@ -2071,7 +2093,7 @@
                 break;
             case 'i':
                 if (posting == 1)
-                err("Cannot mix POST and HEAD\n");
+                err("Cannot mix PUT, POST and HEAD\n");
                 posting = -1;
                 break;
             case 'g':
@@ -2088,7 +2110,7 @@
                 break;
             case 'p':
                 if (posting != 0)
-                    err("Cannot mix POST and HEAD\n");
+                    err("Cannot mix PUT, POST and HEAD\n");
                 if (0 == (r = open_postfile(optarg))) {
                     posting = 1;
                 }
@@ -2096,6 +2118,16 @@
                     exit(r);
                 }
                 break;
+            case 'u':
+                if (posting != 0)
+                    err("Cannot mix PUT, POST and HEAD\n");
+                if (0 == (r = open_postfile(optarg))) {
+                    posting = 2;
+                }
+                else if (postdata) {
+                    exit(r);
+                }
+                break;
             case 'r':
                 recverrok = 1;
                 break;


--- On Mon, 8/17/09, Philip M. Gollucci <pgollucci@p6m7g8.com> wrote:

> From: Philip M. Gollucci <pgollucci@p6m7g8.com>
> Subject: Re: ab
> To: dev@httpd.apache.org
> Date: Monday, August 17, 2009, 7:28 PM
> Jeff Barnes wrote:
> > A need arose for my organization to be able to load
> test web services. I modified ab.c to be able to send HTTP
> PUT requests.
> > 
> > We have been using it for a couple of weeks and it is
> performing as expected. I would be happy to provide the
> changes (minor, it mimics POST requests).
> > 
> > Would it be appropriate for me to post the svn diff to
> this list?
> > 
> > Best regards,
> > Jeff Barnes
> > 
> > 
> Please do so.
> 
> 

Mime
View raw message