From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-apps@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH setup 5/9] Allow user-agent string to be customized
Date: Tue, 06 Jun 2017 11:55:00 -0000 [thread overview]
Message-ID: <20170606115432.105020-6-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20170606115432.105020-1-jon.turney@dronecode.org.uk>
If the option is present without a string, this means that no user-agent
header should be added.
Also include version in default user agent string
v2:
Add logging of User-Agent: header override
v3:
Be more careful about scope User-Agent std::string object
---
nio-ie5.cc | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/nio-ie5.cc b/nio-ie5.cc
index 7708d4c..24d2c13 100644
--- a/nio-ie5.cc
+++ b/nio-ie5.cc
@@ -27,6 +27,11 @@
#include "netio.h"
#include "nio-ie5.h"
#include "LogSingleton.h"
+#include "setup_version.h"
+#include "getopt++/StringOption.h"
+
+static StringOption UserAgent ("", '\0', "user-agent", "User agent string for HTTP requests");
+static std::string default_useragent = std::string("Cygwin-Setup/") + setup_version;
static HINTERNET internet_direct = 0;
static HINTERNET internet_preconfig = 0;
@@ -45,7 +50,27 @@ NetIO (_url)
if (*internet == 0)
{
InternetAttemptConnect (0);
- *internet = InternetOpen ("Cygwin Setup",
+
+ const char *lpszAgent = default_useragent.c_str();
+ if (UserAgent.isPresent())
+ {
+ const std::string &user_agent = UserAgent;
+ if (user_agent.length())
+ {
+ // override the default user agent string
+ lpszAgent = user_agent.c_str();
+ Log (LOG_PLAIN) << "User-Agent: header overridden to \"" << lpszAgent << "\"" << endLog;
+ }
+ else
+ {
+ // user-agent option is present, but no string is specified means
+ // don't add a user-agent header
+ lpszAgent = NULL;
+ Log (LOG_PLAIN) << "User-Agent: header suppressed " << lpszAgent << endLog;
+ }
+ }
+
+ *internet = InternetOpen (lpszAgent,
direct ? INTERNET_OPEN_TYPE_DIRECT : INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
}
--
2.12.3
next prev parent reply other threads:[~2017-06-06 11:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-06 11:54 [PATCH setup 0/9] Setup patches Jon Turney
2017-06-06 11:54 ` [PATCH setup 2/9] Alphabetically sort options in usage help Jon Turney
2017-06-06 11:54 ` [PATCH setup 4/9] Add Option::isPresent() method Jon Turney
2017-06-06 11:55 ` [PATCH setup 9/9] Avoid messagebox spam with file:// protocol URLs Jon Turney
2017-06-06 11:55 ` Jon Turney [this message]
2017-06-06 11:55 ` [PATCH setup 8/9] Fix useless error message Jon Turney
2017-06-06 11:55 ` [PATCH setup 1/9] Allow options which only have long names Jon Turney
2017-06-06 11:55 ` [PATCH setup 6/9] Allow click-to-activate in PickView list control Jon Turney
2017-06-06 11:55 ` [PATCH setup 7/9] Fix that clicking on any column changes "Keep" to "Uninstall" Jon Turney
2017-06-06 11:55 ` [PATCH setup 3/9] Access StringOption's value by reference Jon Turney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170606115432.105020-6-jon.turney@dronecode.org.uk \
--to=jon.turney@dronecode.org.uk \
--cc=cygwin-apps@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).