71 #define MAX_THREADS 1024    72 #define MAX_IN_QUEUE 128    98         panic(0, 
"Cannot read content text");
    99     debug(
"", 0, 
"body content is");
   117     while (*pattern != 
'\0') {
   118         n = strcspn(pattern, 
"%");
   121         gw_assert(*pattern == 
'%' || *pattern == 
'\0');
   122         if (*pattern == 
'\0')
   150             warning(0, 
"Unknown escape code (%%%c) within URL, skipping!", *pattern);
   167     info(0, 
"Starting fetch %ld", i);
   168     id = gw_malloc(
sizeof(
long));
   201     debug(
"", 0, 
"Started request %ld with url:", *
id);
   223     if (
id == NULL || ret == -1) {
   224     error(0, 
"http GET failed");
   228     debug(
"", 0, 
"Done with request %ld", *(
long *) 
id);
   232     debug(
"", 0, 
"Content-type is <%s>, charset is <%s>",
   238         debug(
"", 0, 
"Reply headers:");
   246         debug(
"", 0, 
"Reply body:");
   259     long succeeded, failed;
   293     while (in_queue > 0) {
   304     info(0, 
"This thread: %ld succeeded, %ld failed.", succeeded, failed);
   315     for (pos = 0; pos < 
octstr_len(headers); pos++) {
   334     info(0, 
"Usage: test_http [options] url ...");
   335     info(0, 
"where options are:");
   336     info(0, 
"-v number");
   337     info(0, 
"    set log level for stderr logging");
   339     info(0, 
"    don't print the body or headers of the HTTP response");
   340     info(0, 
"-r number");
   341     info(0, 
"    make `number' requests, repeating URLs as necessary");
   342     info(0, 
"-t number");
   343     info(0, 
"    run `number' threads, that make -r `number' requests");
   344     info(0, 
"-i interval");
   345     info(0, 
"    make one request in `interval' seconds");
   346     info(0, 
"-p domain.name");
   347     info(0, 
"    use `domain.name' as a proxy");
   348     info(0, 
"-P portnumber");
   349     info(0, 
"    connect to proxy at port `portnumber'");
   351     info(0, 
"    proxy exceptions as regex value");
   353     info(0, 
"    use HTTPS scheme to access SSL-enabled proxy server");
   354     info(0, 
"-e domain1:domain2:...");
   355     info(0, 
"    set exception list for proxy use");
   356     info(0, 
"-u filename");
   357     info(0, 
"    read request's &text= string from file 'filename'. It is"); 
   358     info(0, 
"    url encoded before it is added to the request");
   359     info(0, 
"-H filename");
   360     info(0, 
"    read HTTP headers from file 'filename' and add them to");
   361     info(0, 
"    the request for url 'url'");
   362     info(0, 
"-B filename");
   363     info(0, 
"    read content from file 'filename' and send it as body");
   364     info(0, 
"    of a POST method request (default: GET if no -B is set)");
   365     info(0, 
"-m method");
   366     info(0, 
"    use a specific HTTP method for request to server");
   368     info(0, 
"    use HTTPS scheme to access SSL-enabled HTTP server");
   369     info(0, 
"-c ssl_client_cert_key_file");
   370     info(0, 
"    use this file as the SSL certificate and key file");
   371     info(0, 
"-C ssl_ca_file");
   372     info(0, 
"    use this file as the SSL certificate authority");
   374     info(0, 
"    don't follow redirects");
   376     info(0, 
"    evaluate for URL escape code patterns (%%r - random number,");
   377     info(0, 
"    %%I - UUID string)");
   380 int main(
int argc, 
char **argv) 
   382     int i, opt, num_threads;
   405     exceptions_regex = NULL;
   410     while ((opt = 
getopt(argc, argv, 
"hv:qr:p:P:Se:t:i:a:u:sc:H:B:m:fVC:")) != EOF) {
   425         num_threads = atoi(
optarg);
   438             panic(0, 
"Cannot open message text file %s", 
optarg);
   441             panic(0, 
"Cannot read message text");
   442         debug(
"", 0, 
"message text is");
   468         p = strtok(NULL, 
":");
   480         p = strtok(NULL, 
"");
   498             panic(0, 
"Cannot open header text file %s", 
optarg);
   501             panic(0, 
"Cannot read header text");
   502         debug(
"", 0, 
"headers are");
   527         conn_use_global_trusted_ca_file(ca_file);
   534         error(0, 
"Invalid option %c", opt);
   536         panic(0, 
"Stopping.");
   554             panic(0, 
"client certkey file need to be given!");
   577     if (num_threads == 1)
   580         for (i = 0; i < num_threads; ++i)
   582         for (i = 0; i < num_threads; ++i)
   587     run_time = difftime(end, 
start);
   588     info(0, 
"%ld requests in %f seconds, %f requests/s.",
 void error(int err, const char *fmt,...)
 
void info(int err, const char *fmt,...)
 
void octstr_append_data(Octstr *ostr, const char *data, long len)
 
void http_header_add(List *headers, char *name, char *contents)
 
static Octstr * method_name
 
gw_assert(wtls_machine->packet_to_send !=NULL)
 
void counter_destroy(Counter *counter)
 
static void split_headers(Octstr *headers, List **split)
 
void gwlist_append(List *list, void *item)
 
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
 
static Octstr * auth_password
 
void gwthread_join(long thread)
 
static HTTPCaller * caller
 
static void client_thread(void *arg)
 
void http_header_combine(List *old_headers, List *new_headers)
 
static Octstr * extra_headers
 
int octstr_url_decode(Octstr *ostr)
 
void http_add_basic_auth(List *headers, Octstr *username, Octstr *password)
 
void uuid_unparse(const uuid_t uu, char *out)
 
void uuid_generate(uuid_t out)
 
void http_header_get_content_type(List *headers, Octstr **type, Octstr **charset)
 
int http_name2method(Octstr *method)
 
void octstr_append_cstr(Octstr *ostr, const char *cstr)
 
static void url_pattern(Octstr *url)
 
#define octstr_get_cstr(ostr)
 
#define octstr_copy(ostr, from, len)
 
unsigned long counter_increase(Counter *counter)
 
int main(int argc, char **argv)
 
void http_destroy_headers(List *headers)
 
static Octstr * ssl_client_certkey_file
 
static int follow_redirect
 
int getopt(int argc, char **argv, char *opts)
 
void http_start_request(HTTPCaller *caller, int method, Octstr *url, List *headers, Octstr *body, int follow, void *id, Octstr *certkeyfile)
 
Octstr * octstr_imm(const char *cstr)
 
Counter * counter_create(void)
 
static Octstr * auth_username
 
void * gwlist_extract_first(List *list)
 
void log_set_output_level(enum output_level level)
 
static Octstr * content_file
 
#define octstr_duplicate(ostr)
 
#define octstr_dump(ostr, level,...)
 
void warning(int err, const char *fmt,...)
 
void octstr_destroy(Octstr *ostr)
 
static Octstr * proxy_username
 
#define gwthread_create(func, arg)
 
#define octstr_create(cstr)
 
void octstr_destroy_item(void *os)
 
static int receive_reply(HTTPCaller *caller)
 
void gwthread_sleep(double seconds)
 
#define http_receive_result(caller, status, final_url, headers, body)
 
Octstr * octstr_read_file(const char *filename)
 
long octstr_len(const Octstr *ostr)
 
void http_use_proxy(Octstr *hostname, int port, int ssl, List *exceptions, Octstr *username, Octstr *password, Octstr *exceptions_regex)
 
void debug(const char *place, int err, const char *fmt,...)
 
HTTPCaller * http_caller_create(void)
 
void octstr_format_append(Octstr *os, const char *fmt,...)
 
void gwlib_shutdown(void)
 
static Octstr * post_content_create(void)
 
void octstr_truncate(Octstr *ostr, int new_len)
 
void http_caller_destroy(HTTPCaller *caller)
 
static void start_request(HTTPCaller *caller, List *reqh, long i)
 
int octstr_get_char(const Octstr *ostr, long pos)
 
void octstr_url_encode(Octstr *ostr)
 
static Octstr * proxy_password
 
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)