Setup is sending User-Agent header if direct connection or system proxy
is used, but not when direct(legacy) or setup-specific proxy. Fix this.
---
Makefile.am | 2 ++
nio-http.cc | 4 +++
nio-ie5.cc | 53 ++---
useragent.cc | 109 +++
useragent.h | 8 +
5 files changed, 125 insertions(+), 51 deletions(-)
create mode 100644 useragent.cc
create mode 100644 useragent.h
diff --git a/Makefile.am b/Makefile.am
index a238d88..3c88020 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -256,6 +256,8 @@ inilint_SOURCES = \
String++.h \
threebar.cc \
threebar.h \
+ useragent.cc \
+ useragent.h \
UserSettings.cc \
UserSettings.h \
win32.cc \
diff --git a/nio-http.cc b/nio-http.cc
index 413ee7f..3f7fd9b 100644
--- a/nio-http.cc
+++ b/nio-http.cc
@@ -29,6 +29,8 @@
#include "netio.h"
#include "nio-http.h"
+#include "useragent.h"
+
#ifndef _strnicmp
#define _strnicmp strncasecmp
#endif
@@ -125,6 +127,8 @@ retry_get:
s->printf ("Proxy-Authorization: Basic %s\r\n",
base64_encode (net_proxy_user, net_proxy_passwd));
+ s->printf ("%s", get_useragent_header());
+
s->printf ("\r\n");
char * l = s->gets ();
diff --git a/nio-ie5.cc b/nio-ie5.cc
index a649233..2e36ac6 100644
--- a/nio-ie5.cc
+++ b/nio-ie5.cc
@@ -27,42 +27,12 @@
#include "netio.h"
#include "nio-ie5.h"
#include "LogSingleton.h"
-#include "setup_version.h"
-#include "getopt++/StringOption.h"
+#include "useragent.h"
#include
-static StringOption UserAgent ("", '\0', "user-agent", "User agent string for
HTTP requests");
-
static HINTERNET internet_direct = 0;
static HINTERNET internet_preconfig = 0;
-const std::string &
-determine_default_useragent(void)
-{
- static std::string default_useragent;
-
- if (!default_useragent.empty())
-return default_useragent;
-
- std::stringstream os;
- os << "Windows NT " << OSMajorVersion() << "." << OSMinorVersion() << "." <<
OSBuildNumber();
-
- std::string bitness = "Unknown";
-#ifdef __x86_64__
- bitness = "Win64";
-#else
- typedef BOOL (WINAPI *PFNISWOW64PROCESS)(HANDLE, PBOOL);
- PFNISWOW64PROCESS pfnIsWow64Process =
(PFNISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"),
"IsWow64Process");
- if (pfnIsWow64Process) {
-BOOL bIsWow64 = FALSE;
-if (pfnIsWow64Process(GetCurrentProcess(), ))
- bitness = bIsWow64 ? "WoW64" : "Win32";
- }
-#endif
- default_useragent = std::string("Cygwin-Setup/") + setup_version + " (" +
os.str() + ";" + bitness + ")";
- return default_useragent;
-}
-
NetIO_IE5::NetIO_IE5 (char const *_url, bool direct, bool cachable):
NetIO (_url)
{
@@ -78,26 +48,7 @@ NetIO (_url)
{
InternetAttemptConnect (0);
- const char *lpszAgent = determine_default_useragent().c_str();
- if (UserAgent.isPresent())
-{
- const std::string _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,
+ *internet = InternetOpen (get_useragent(),
direct ? INTERNET_OPEN_TYPE_DIRECT :
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
}
diff --git a/useragent.cc b/useragent.cc
new file mode 100644
index 000..a871a8b
--- /dev/null
+++ b/useragent.cc
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2000, Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * A copy of the GNU General Public License can be found at
+ * http://www.gnu.org/
+ *
+ * Written by DJ Delorie
+ *
+ */
+
+#include "win32.h"
+
+#include "LogSingleton.h"
+#include "setup_version.h"
+#include "getopt++/StringOption.h"
+#include "useragent.h"
+#include
+
+static StringOption UserAgentOption ("", '\0', "user-agent", "User agent
string for HTTP requests");
+
+const std::string &
+determine_default_useragent(void)
+{
+ static std::string default_useragent;
+
+ if (!default_useragent.empty())
+return default_useragent;
+
+ std::stringstream os;
+ os << "Windows NT " << OSMajorVersion() << "." << OSMinorVersion() << "." <<
OSBuildNumber();
+
+ std::string bitness =