--- ab.orig	2013-12-30 15:29:45.000000000 +0200
+++ ab.c	2015-06-12 17:29:15.000000000 +0300
@@ -264,12 +264,14 @@
 
 /* --------------------- GLOBALS ---------------------------- */
 
+int r = 0;      /* result of read request files */
 int verbosity = 0;      /* no verbosity by default */
 int recverrok = 0;      /* ok to proceed after socket receive errors */
 enum {NO_METH = 0, GET, HEAD, PUT, POST} method = NO_METH;
 const char *method_str[] = {"bug", "GET", "HEAD", "PUT", "POST"};
 int send_body = 0;      /* non-zero if sending body with request */
 int requests = 1;       /* Number of requests to make */
+int request_append = 0; /* Whether extra data needs to be appended to requests */
 int heartbeatres = 100; /* How often do we say we're alive */
 int concurrency = 1;    /* Number of multiple requests to make */
 int percentile = 1;     /* Show percentile served */
@@ -282,8 +284,15 @@
 char *hostname;         /* host name from URL */
 const char *host_field;       /* value of "Host:" header field */
 const char *path;             /* path name */
-char *postdata;         /* *buffer containing data from postfile */
+char postdata[1000];         /* *buffer containing data from postfile */
 apr_size_t postlen = 0; /* length of data to be POSTed */
+char *reqdata;          /* *buffer containing data from request file */
+char *req_p;            /* pointer to position in request data */
+int post_line = 0;            /* line in post data */
+enum { MAXLINES = 1000 };   /*  max lines in postfile*/
+int post_lines = 0;             /* real lines in postfile */
+char lines[MAXLINES][BUFSIZ];
+apr_size_t append_req_len = 0; /* length of request data to be appended */
 char *content_type = NULL;     /* content type to put in POST header */
 const char *cookie,           /* optional cookie line */
            *auth,             /* optional (basic/uuencoded) auhentication */
@@ -705,6 +714,82 @@
         return;
     }
 
+        char *eol;
+        char path_append[1024];
+        int snprintf_res;
+
+        /* modify request each time to append data from request file */
+        if (request_append == 1) {
+            eol = strchr(req_p, '\n');      /* end of current line */
+            if (eol == NULL)
+                eol = reqdata + append_req_len;    /* end of reqdata */
+
+            apr_snprintf(path_append, eol-req_p+1, "%s", req_p);
+
+            req_p = eol + 1;    /* next line */
+            if (req_p >= (reqdata + append_req_len))
+                req_p = reqdata;    /* back to start of request data */
+
+            if (send_body <= 0) {
+                snprintf_res = apr_snprintf(request, sizeof(_request),
+                    "%s %s%s HTTP/1.0\r\n"
+                    "User-Agent: ApacheBench/%s\r\n"
+                    "%s" "%s" "%s"
+                    "Host: %s%s\r\n"
+                    "Accept: */*\r\n"
+                    "%s" "\r\n",
+                    (send_body == 0) ? "GET" : "HEAD",
+                    (isproxy) ? fullurl : path,
+                    path_append,
+                    AP_AB_BASEREVISION,
+                    keepalive ? "Connection: Keep-Alive\r\n" : "",
+                    cookie, auth, host_field, colonhost, hdrs);
+            }
+            else {
+                snprintf_res = apr_snprintf(request,  sizeof(_request),
+                    "POST %s%s HTTP/1.0\r\n"
+                    "User-Agent: ApacheBench/%s\r\n"
+                    "%s" "%s" "%s"
+                    "Host: %s%s\r\n"
+                    "Accept: */*\r\n"
+                    "Content-length: %" APR_SIZE_T_FMT "\r\n"
+                    "Content-type: %s\r\n"
+                    "%s"
+                    "\r\n",
+                    (isproxy) ? fullurl : path,
+                    path_append,
+                    AP_AB_BASEREVISION,
+                    keepalive ? "Connection: Keep-Alive\r\n" : "",
+                    cookie, auth,
+                    host_field, colonhost, postlen,
+                    (content_type[0]) ? content_type : "text/plain", hdrs);
+            }
+            if (snprintf_res >= sizeof(_request)) {
+                err("Request too long\n");
+            }
+
+            if (verbosity >= 2 && !request_append)
+                printf("INFO: POST header == \n---\n%s\n---\n", request);
+
+            reqlen = strlen(request);
+        }
+
+    /*
+     * Combine headers and (optional) post file into one continuous buffer
+     */
+
+    if (send_body) {
+        char *buff = xmalloc(postlen + reqlen + 1);
+        strcpy(buff, request);
+          printf("Send request timed out!  %s\n", lines[post_line]);
+        memcpy(buff + reqlen, lines[post_line], postlen);
+        request = buff;
+    }
+    post_line++;
+    if (post_line == post_lines){
+        post_line = 0;
+    }
+
     do {
         apr_time_t tnow;
         apr_size_t l = c->rwrite;
@@ -1724,15 +1809,7 @@
 
     reqlen = strlen(request);
 
-    /*
-     * Combine headers and (optional) post file into one continuous buffer
-     */
-    if (send_body) {
-        char *buff = xmalloc(postlen + reqlen + 1);
-        strcpy(buff, request);
-        memcpy(buff + reqlen, postdata, postlen);
-        request = buff;
-    }
+
 
 #ifdef NOT_ASCII
     inbytes_left = outbytes_left = reqlen;
@@ -1782,6 +1859,9 @@
         start_connect(&con[i]);
     }
 
+    if (request_append == 1)
+            req_p = reqdata;
+
     do {
         apr_int32_t n;
         const apr_pollfd_t *pollresults, *pollfd;
@@ -1922,6 +2002,7 @@
     fprintf(stderr, "    -b windowsize   Size of TCP send/receive buffer, in bytes\n");
     fprintf(stderr, "    -B address      Address to bind to when making outgoing connections\n");
     fprintf(stderr, "    -p postfile     File containing data to POST. Remember also to set -T\n");
+    fprintf(stderr, "    -R reqfile      File containing lines to append to each request URL\n");
     fprintf(stderr, "    -u putfile      File containing data to PUT. Remember also to set -T\n");
     fprintf(stderr, "    -T content-type Content-type header to use for POST/PUT data, eg.\n");
     fprintf(stderr, "                    'application/x-www-form-urlencoded'\n");
@@ -2066,17 +2147,58 @@
         return rv;
     }
     postlen = (apr_size_t)finfo.size;
-    postdata = xmalloc(postlen);
-    rv = apr_file_read_full(postfd, postdata, postlen, NULL);
+         FILE *fp = fopen(pfile, "r");
+        while (post_lines < MAXLINES && fgets(lines[post_lines], sizeof(lines[0]), fp))
+        {
+            lines[post_lines][strlen(lines[post_lines])-1] = '\0';
+            post_lines = post_lines + 1;
+        }
+
+    apr_file_close(postfd);
+    return APR_SUCCESS;
+}
+
+
+
+/* Open a file containing lines to append to each request
+ * For -R option.
+ */
+static int open_request_file(const char *rfile)
+{
+    apr_file_t *reqfd;
+    apr_finfo_t finfo;
+    apr_status_t rv;
+    char errmsg[120];
+
+    rv = apr_file_open(&reqfd, rfile, APR_READ, APR_OS_DEFAULT, cntxt);
     if (rv != APR_SUCCESS) {
-        fprintf(stderr, "ab: Could not read POST data file: %s\n",
+        fprintf(stderr, "ab: Could not open POST data file (%s): %s\n", rfile,
                 apr_strerror(rv, errmsg, sizeof errmsg));
         return rv;
     }
-    apr_file_close(postfd);
-    return APR_SUCCESS;
+
+    apr_file_info_get(&finfo, APR_FINFO_NORM, reqfd);
+    append_req_len = (apr_size_t)finfo.size;
+    reqdata = malloc(append_req_len+2);
+    if (!reqdata) {
+        fprintf(stderr, "ab: Could not allocate request data buffer\n");
+        return APR_ENOMEM;
+    }
+    rv = apr_file_read_full(reqfd, reqdata, append_req_len, NULL);
+    if (rv != APR_SUCCESS) {
+        fprintf(stderr, "ab: Could not read request data file: %s\n",
+                apr_strerror(rv, errmsg, sizeof errmsg));
+        return rv;
+    }
+    apr_file_close(reqfd);
+    if (*(reqdata + append_req_len-1) != '\n')
+        *(reqdata + (append_req_len++) - 1) = '\n';
+    *(reqdata + append_req_len) = '\0';
+
+    return 0;
 }
 
+
 /* ------------------------------------------------------- */
 
 /* sort out command-line args and call test */
@@ -2127,7 +2249,7 @@
     myhost = NULL; /* 0.0.0.0 or :: */
 
     apr_getopt_init(&opt, cntxt, argc, argv);
-    while ((status = apr_getopt(opt, "n:c:t:s:b:T:p:u:v:lrkVhwix:y:z:C:H:P:A:g:X:de:SqB:"
+    while ((status = apr_getopt(opt, "n:c:t:s:b:T:p:u:v:lrkVhwix:y:z:C:H:P:A:g:X:de:SqBR:"
 #ifdef USE_SSL
             "Z:f:"
 #endif
@@ -2171,6 +2293,16 @@
             case 's':
                 aprtimeout = apr_time_from_sec(atoi(opt_arg)); /* timeout value */
                 break;
+            case 'R':
+                // if (posting > 0)
+                //     err("-R only applicable for non-POST requests\n");
+                if (0 == (r = open_request_file(optarg))) {
+                    request_append = 1;
+                }
+                else {
+                    exit(r);
+                }
+                break;
             case 'p':
                 if (method != NO_METH)
                     err("Cannot mix POST with other methods\n");
