diff options
author | Jeff Trawick <trawick@apache.org> | 2009-09-27 02:28:27 +0200 |
---|---|---|
committer | Jeff Trawick <trawick@apache.org> | 2009-09-27 02:28:27 +0200 |
commit | e738bd820b9f2f91c487acdb70b9163d714603da (patch) | |
tree | 04c259f4f712354d7237c43558b9191c9b71e5b7 /support | |
parent | * Use strcasecmp instead of strncasecmp as we want to be sure that the whole (diff) | |
download | apache2-e738bd820b9f2f91c487acdb70b9163d714603da.tar.xz apache2-e738bd820b9f2f91c487acdb70b9163d714603da.zip |
small code cleanups for POST/PUT, especially to combine common code
exit if the file to POST/PUT can't be read
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@819239 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'support')
-rw-r--r-- | support/ab.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/support/ab.c b/support/ab.c index 291456e238..fdbe84cde8 100644 --- a/support/ab.c +++ b/support/ab.c @@ -670,7 +670,7 @@ static void write_request(struct connection * c) c->connect = tnow; c->rwrote = 0; c->rwrite = reqlen; - if (posting) + if (posting > 0) c->rwrite += postlen; } else if (tnow > c->connect + aprtimeout) { @@ -788,10 +788,10 @@ static void output_results(int sig) if (keepalive) printf("Keep-Alive requests: %d\n", doneka); printf("Total transferred: %" APR_INT64_T_FMT " bytes\n", totalread); - if (posting == 1) - printf("Total POSTed: %" APR_INT64_T_FMT "\n", totalposted); - if (posting == 2) - printf("Total PUT: %" APR_INT64_T_FMT "\n", totalposted); + if (posting > 0) + printf("Total %s %" APR_INT64_T_FMT "\n", + posting == 1 ? "POSTed:" : "PUT: ", + totalposted); printf("HTML transferred: %" APR_INT64_T_FMT " bytes\n", totalbread); /* avoid divide by zero */ @@ -1075,14 +1075,12 @@ static void output_html_results(void) 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 == 1) - printf("<tr %s><th colspan=2 %s>Total POSTed:</th>" + if (posting > 0) + printf("<tr %s><th colspan=2 %s>Total %s:</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); + trstring, tdstring, + posting == 1 ? "POSTed" : "PUT", + 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); @@ -1646,14 +1644,14 @@ static void test(void) if (verbosity >= 2) printf("INFO: %s header == \n---\n%s\n---\n", - (posting == 2) ? "PUT" : "POST", request); + (posting == 2) ? "PUT" : "POST", request); /* FIXME for GET and HEAD */ reqlen = strlen(request); /* - * Combine headers and (optional) post file into one contineous buffer + * Combine headers and (optional) post file into one continuous buffer */ - if (posting >= 1) { + if (posting > 0) { char *buff = malloc(postlen + reqlen + 1); if (!buff) { fprintf(stderr, "error creating request buffer: out of memory\n"); @@ -1947,9 +1945,9 @@ static int parse_url(char *url) /* ------------------------------------------------------- */ -/* read data to POST from file, save contents and length */ +/* read data to POST/PUT from file, save contents and length */ -static int open_postfile(const char *pfile) +static apr_status_t open_postfile(const char *pfile) { apr_file_t *postfd; apr_finfo_t finfo; @@ -1982,7 +1980,7 @@ static int open_postfile(const char *pfile) return rv; } apr_file_close(postfd); - return 0; + return APR_SUCCESS; } /* ------------------------------------------------------- */ @@ -1990,7 +1988,7 @@ static int open_postfile(const char *pfile) /* sort out command-line args and call test */ int main(int argc, const char * const argv[]) { - int r, l; + int l; char tmp[1024]; apr_status_t status; apr_getopt_t *opt; @@ -2080,22 +2078,18 @@ int main(int argc, const char * const argv[]) case 'p': if (posting != 0) err("Cannot mix POST and HEAD\n"); - if (0 == (r = open_postfile(optarg))) { - posting = 1; - } - else if (postdata) { - exit(r); + if ((status = open_postfile(optarg)) != APR_SUCCESS) { + exit(1); } + posting = 1; 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); + if ((status = open_postfile(optarg)) != APR_SUCCESS) { + exit(1); } + posting = 2; break; case 'r': recverrok = 1; |