]> 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>
Thu, 17 Feb 2011 14:37:38 +0000 (03:37 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 17 Feb 2011 14:37:38 +0000 (03:37 +1300)
tools/squidclient.1
tools/squidclient.cc

index 657c1e1ff78abba63817b60f59234e6488c4e53b..0ced982c4db467f234ff109d7ea127dc1c9419d2 100644 (file)
@@ -7,7 +7,9 @@ A simple HTTP web client tool
 .
 .SH SYNOPSIS
 .if !'po4a'hide' .B squidclient
-.if !'po4a'hide' .B "[ \-arsv ] [ \-g"
+.if !'po4a'hide' .B "[ \-arsv ] [ \-A"
+string
+.if !'po4a'hide' .B "] [ \-g"
 count
 .if !'po4a'hide' .B "] [ \-h"
 remote host
@@ -61,6 +63,12 @@ proxy object cache and management information are provided.
 Do NOT include Accept: header.
 .
 .if !'po4a'hide' .TP
+.if !'po4a'hide' .B "\-A 'string'"
+Send 
+.B string
+as User-Agent: header. To omit the header completely set string to empty ('').
+.
+.if !'po4a'hide' .TP
 .if !'po4a'hide' .B "\-g count"
 Ping mode, perform
 .I count
index f70ed716641b44285675b6913c5a07ce3bb06138..16a8d6794c65b6afd1f3dacd04fad4d4835f1ef5 100644 (file)
@@ -161,7 +161,7 @@ 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] "
 #if HAVE_GSSAPI
             "[-n] [-N] "
@@ -171,6 +171,7 @@ usage(const char *progname)
             "\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"
@@ -230,6 +231,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";
@@ -253,9 +255,9 @@ main(int argc, char *argv[])
         if (url[0] == '-')
             usage(argv[0]);
 #if HAVE_GSSAPI
-        while ((c = getopt(argc, argv, "ah:j:V:l:P:i:km:p:rsvt:g:p:I:H:T:u:U:w:W:nN?")) != -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:nN?")) != -1)
 #else
-        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)
 #endif
             switch (c) {
 
@@ -263,6 +265,11 @@ main(int argc, char *argv[])
                 opt_noaccept = 1;
                 break;
 
+            case 'A':
+                if (optarg != NULL)
+                    useragent = optarg;
+                break;
+
             case 'h':          /* remote host */
                 if (optarg != NULL)
                     hostname = optarg;
@@ -434,6 +441,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);