]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
squidclient: send User-Agent header and -A option to alter it
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 30 Mar 2011 12:35:36 +0000 (06:35 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 30 Mar 2011 12:35:36 +0000 (06:35 -0600)
tools/squidclient.1
tools/squidclient.cc

index ec66367af7c8ab0da5343d7271b3d6619e19884f..5a9578bbeafc0bf026e2e9428d13639c044a58ad 100644 (file)
@@ -3,8 +3,9 @@
 squidclient -- a simple HTTP web client
 .SH SYNOPSIS
 .B squidclient
-.RB [ \-arsv ]
-.RB [ \-g
+.RB [ \-arsv ] [ \-A
+.IR string
+.RB ] [ \-g
 .IR count ]
 .RB [ \-h
 .IR remote\-host ]
@@ -50,6 +51,10 @@ proxy object cache and management information are provided.
 .SH OPTIONS
 .IP "\-a"
 Do NOT include Accept: header.
+.IP "\-A 'string'"
+Send 
+.B string
+as User-Agent: header. To omit the header completely set string to empty ('').
 .IP "\-g \fIcount\fP"
 Ping mode, perform
 .I count
index a7c7b59be67ff63771d17d9cd69c96ee222ee931..32af31ff8d2d868cb4817f1addd257f07fb2a294 100644 (file)
@@ -132,12 +132,13 @@ usage(const char *progname)
 {
     fprintf(stderr,
             "Version: %s\n"
-            "Usage: %s [-arsv] [-g count] [-h remote host] [-H 'string'] [-i IMS] [-I ping-interval] [-j 'Host-header']"
+            "Usage: %s [-arsv] [-A 'string'] [-g count] [-h remote host] [-H 'string'] [-i IMS] [-I ping-interval] [-j 'Host-header']"
             "[-k] [-l local-host] [-m method] [-p port] [-P file] [-t count] [-T timeout] [-u proxy-user] [-U www-user] "
             "[-V version] [-w proxy-password] [-W www-password] url\n"
             "\n"
             "Options:\n"
             "    -a           Do NOT include Accept: header.\n"
+            "    -A           User-Agent: header. Use \"\" to omit.\n"
             "    -g count     Ping mode, perform \"count\" iterations (0 to loop until interrupted).\n"
             "    -h host      Retrieve URL from cache on hostname.  Default is localhost.\n"
             "    -H 'string'  Extra headers to send. Use '\\n' for new lines.\n"
@@ -192,6 +193,7 @@ main(int argc, char *argv[])
     const char *www_password = NULL;
     const char *host = NULL;
     const char *version = "1.0";
+    const char *useragent = NULL;
 
     /* set the defaults */
     hostname = "localhost";
@@ -213,13 +215,18 @@ main(int argc, char *argv[])
         if (url[0] == '-')
             usage(argv[0]);
 
-        while ((c = getopt(argc, argv, "ah:j:V:l:P:i:km:p:rsvt:g:p:I:H:T:u:U:w:W:?")) != -1)
+        while ((c = getopt(argc, argv, "aA:h:j:V:l:P:i:km:p:rsvt:g:p:I:H:T:u:U:w:W:?")) != -1)
             switch (c) {
 
             case 'a':
                 opt_noaccept = 1;
                 break;
 
+            case 'A':
+                if (optarg != NULL)
+                    useragent = optarg;
+                break;
+
             case 'h':          /* remote host */
                 if (optarg != NULL)
                     hostname = optarg;
@@ -383,6 +390,14 @@ main(int argc, char *argv[])
             strcat(msg,buf);
         }
 
+        if (useragent == NULL) {
+            snprintf(buf, BUFSIZ, "User-Agent: squidclient/%s\r\n", VERSION);
+            strcat(msg,buf);
+        } else if (useragent[0] != '\0') {
+            snprintf(buf, BUFSIZ, "User-Agent: %s\r\n", useragent);
+            strcat(msg,buf);
+        }
+
         if (reload) {
             snprintf(buf, BUFSIZ, "Pragma: no-cache\r\n");
             strcat(msg, buf);