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 Fri, 04 Sep 2009 16:19:13 GMT
Apparently my last submission to the list was a patch for a fork of ab (http://code.google.com/p/apachebench-standalone/wiki/HowToBuild).

Sorry for the confusion (mine). Please find the attached svn diff for the *correct* ab.c and
ab.8. (http://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x/support/ab.c and http://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x/docs/ab.8).

To recap, I added support for HTTP PUT requests to ab and updated the man page. I hope you
find the changes useful.

Also, I have inlined the diffs to this email message.

Regards,
Jeff


ndex: support/ab.c
===================================================================
--- support/ab.c        (revision 808959)
+++ support/ab.c        (working copy)
@@ -763,8 +763,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);
+    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 */
@@ -1048,10 +1050,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);
+    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);
@@ -1606,12 +1612,13 @@
     }
     else {
         snprintf_res = apr_snprintf(request,  sizeof(_request),
-            "POST %s HTTP/1.0\r\n"
+            "%s %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",
+            (posting == 1) ? "POST" : "PUT",
             (isproxy) ? fullurl : path,
             keepalive ? "Connection: Keep-Alive\r\n" : "",
             cookie, auth,
@@ -1623,14 +1630,15 @@
     }

     if (verbosity >= 2)
-        printf("INFO: POST header == \n---\n%s\n---\n", request);
+        printf("INFO: %s header == \n---\n%s\n---\n", 
+                (posting == 2) ? "PUT" : "POST", request);

     reqlen = strlen(request);

     /*
      * 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");
@@ -1831,6 +1839,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 putfile      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");
@@ -2022,7 +2031,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
@@ -2047,8 +2056,8 @@
                 windowsize = atoi(optarg);
                 break;
             case 'i':
-                if (posting == 1)
-                err("Cannot mix POST and HEAD\n");
+                if (posting > 0)
+                err("Cannot mix POST/PUT and HEAD\n");
                 posting = -1;
                 break;
             case 'g':
@@ -2073,6 +2082,16 @@
                     exit(r);
                 }
                 break;
+            case 'u':
+                if (posting != 0)
+                    err("Cannot mix PUT and HEAD\n");
+                if (0 == (r = open_postfile(optarg))) {
+                    posting = 2;
+                }
+                else if (postdata) {
+                    exit(r);
+                }
+                break;
             case 'r':
                 recverrok = 1;
                 break;



Index: docs/man/ab.8 
===================================================================
--- docs/man/ab.8       (revision 808959)
+++ docs/man/ab.8       (working copy)
@@ -27,7 +27,7 @@
 .SH "SYNOPSIS"
  
 .PP
-\fBab\fR [ -\fBA\fR \fIauth-username\fR:\fIpassword\fR ] [ -\fBb\fR \fIwindowsize\fR ] [
-\fBc\fR \fIconcurrency\fR ] [ -\fBC\fR \fIcookie-name\fR=\fIvalue\fR ] [ -\fBd\fR ] [ -\fBe\fR
\fIcsv-file\fR ] [ -\fBf\fR \fIprotocol\fR ] [ -\fBg\fR \fIgnuplot-file\fR ] [ -\fBh\fR ]
[ -\fBH\fR \fIcustom-header\fR ] [ -\fBi\fR ] [ -\fBk\fR ] [ -\fBn\fR \fIrequests\fR ] [ -\fBp\fR
\fIPOST-file\fR ] [ -\fBP\fR \fIproxy-auth-username\fR:\fIpassword\fR ] [ -\fBq\fR ] [ -\fBr\fR
] [ -\fBs\fR ] [ -\fBS\fR ] [ -\fBt\fR \fItimelimit\fR ] [ -\fBT\fR \fIcontent-type\fR ] [
-\fBv\fR \fIverbosity\fR] [ -\fBV\fR ] [ -\fBw\fR ] [ -\fBx\fR \fI<table>-attributes\fR
] [ -\fBX\fR \fIproxy\fR[:\fIport\fR] ] [ -\fBy\fR \fI<tr>-attributes\fR ] [ -\fBz\fR
\fI<td>-attributes\fR ] [ -\fBZ\fR \fIciphersuite\fR ] [http[s]://]\fIhostname\fR[:\fIport\fR]/\fIpath\fR
+\fBab\fR [ -\fBA\fR \fIauth-username\fR:\fIpassword\fR ] [ -\fBb\fR \fIwindowsize\fR ] [
-\fBc\fR \fIconcurrency\fR ] [ -\fBC\fR \fIcookie-name\fR=\fIvalue\fR ] [ -\fBd\fR ] [ -\fBe\fR
\fIcsv-file\fR ] [ -\fBf\fR \fIprotocol\fR ] [ -\fBg\fR \fIgnuplot-file\fR ] [ -\fBh\fR ]
[ -\fBH\fR \fIcustom-header\fR ] [ -\fBi\fR ] [ -\fBk\fR ] [ -\fBn\fR \fIrequests\fR ] [ -\fBp\fR
\fIPOST-file\fR ] [ -\fBu\fR \fIPUT-file\fR ] [ -\fBP\fR \fIproxy-auth-username\fR:\fIpassword\fR
] [ -\fBq\fR ] [ -\fBr\fR ] [ -\fBs\fR ] [ -\fBS\fR ] [ -\fBt\fR \fItimelimit\fR ] [ -\fBT\fR
\fIcontent-type\fR ] [ -\fBv\fR \fIverbosity\fR] [ -\fBV\fR ] [ -\fBw\fR ] [ -\fBx\fR \fI<table>-attributes\fR
] [ -\fBX\fR \fIproxy\fR[:\fIport\fR] ] [ -\fBy\fR \fI<tr>-attributes\fR ] [ -\fBz\fR
\fI<td>-attributes\fR ] [ -\fBZ\fR \fIciphersuite\fR ] [http[s]://]\fIhostname\fR[:\fIport\fR]/\fIpath\fR
                 
             
 .SH "SUMMARY"










--- On Tue, 8/18/09, Jeff Barnes <jbarnesweb@yahoo.com> wrote:

> From: Jeff Barnes <jbarnesweb@yahoo.com>
> Subject: Re: ab
> To: dev@httpd.apache.org
> Date: Tuesday, August 18, 2009, 5:22 AM
> 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