MCPcopy Create free account
hub / github.com/apache/trafficserver / read_url_file

Function read_url_file

tools/http_load/http_load.c:625–749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

623}
624
625static void
626read_url_file(char *url_file)
627{
628 char line[5000], hostname[5000];
629 char *http = "http://";
630 int http_len = strlen(http);
631 char *https = "https://";
632 int https_len = strlen(https);
633 int proto_len, host_len;
634 char *cp;
635
636 FILE *fp = fopen(url_file, "r");
637 if (fp == NULL) {
638 perror(url_file);
639 exit(1);
640 }
641
642 max_urls = 100;
643 urls = (url *)malloc_check(max_urls * sizeof(url));
644 num_urls = 0;
645 cur_url = 0;
646
647 /* The Host: header can either be user provided (via -header), or
648 constructed by the URL host and possibly port (if not port 80) */
649
650 char hdr_buf[2048];
651 int hdr_bytes = 0;
652 hdr_bytes += snprintf(&hdr_buf[hdr_bytes], sizeof(hdr_buf) - hdr_bytes, "User-Agent: %s\r\n", user_agent);
653 if (cookie)
654 hdr_bytes += snprintf(&hdr_buf[hdr_bytes], sizeof(hdr_buf) - hdr_bytes, "Cookie: %s\r\n", cookie);
655 if (do_accept_gzip)
656 hdr_bytes += snprintf(&hdr_buf[hdr_bytes], sizeof(hdr_buf) - hdr_bytes, "Accept-Encoding: gzip\r\n");
657 /* Add Connection: keep-alive header if keep_alive requested, and version != "1.1" */
658 if ((keep_alive > 0) && !is_http_1_1)
659 hdr_bytes += snprintf(&hdr_buf[hdr_bytes], sizeof(hdr_buf) - hdr_bytes, "Connection: keep-alive\r\n");
660 if (extra_headers != NULL) {
661 hdr_bytes += snprintf(&hdr_buf[hdr_bytes], sizeof(hdr_buf) - hdr_bytes, "%s\r\n", extra_headers);
662 }
663 snprintf(&hdr_buf[hdr_bytes], sizeof(hdr_buf) - hdr_bytes, "\r\n");
664
665 while (fgets(line, sizeof(line), fp) != (char *)0) {
666 char req_buf[2048];
667 int req_bytes = 0;
668
669 /* Nuke trailing newline. */
670 if (line[strlen(line) - 1] == '\n')
671 line[strlen(line) - 1] = '\0';
672
673 /* Check for room in urls. */
674 if (num_urls >= max_urls) {
675 max_urls *= 2;
676 urls = (url *)realloc_check((void *)urls, max_urls * sizeof(url));
677 }
678
679 /* Add to table. */
680 urls[num_urls].url_str = strdup_check(line);
681
682 /* Parse it. */

Callers 1

mainFunction · 0.85

Calls 4

malloc_checkFunction · 0.85
realloc_checkFunction · 0.85
strdup_checkFunction · 0.85
lookup_addressFunction · 0.85

Tested by

no test coverage detected