rhnlib patch [was Re: [rhn-users] up2date...]
Bob Drzyzgula
redhat at drzyzgula.org
Fri Mar 19 15:12:07 UTC 2004
On Thu, Mar 18, 2004 at 07:31:33PM -0500, Todd Warner wrote:
>
> Patches gladly accepted. Send 'em our way and we'll take a look-see.
> rhnlib and up2date are GPLed software so... there you go.
>
> Definately sounds like something is funky though. I will make sure the
> right people know about it.
>
> --
> ____________
> /odd Warner <taw@{redhat,pobox}.com>
> Bit Twiddler - Operation Cheetah Flip - Red Hat Inc.
> ---------------------gpg info in the message headers--------------------
> "But when you think about it, it's mostly the bad decisions we make
> that change our lives. Good ones just get you home safely." -Chris Bliss
rhnlib patch:
# This is a patch against RHEL 3.0WS rhnlib-1.3
#
# This patch will
# (a) fix a bug which prevented the user agent string from
# being presented in the initial http CONNECT to an
# https proxy.
# (b) add support for a configurable http user agent string
#
# Source files affected by this are
#
# rhn/connections.py
# rhn/rpclib.py
# rhn/transports.py
#
# This patch will slightly change the interface used by the call
# made by up2date to the rpclib.GETServer() interface, by adding
# a new optional parameter "userAgent", which defaults to None.
#
# In addition, there are similar changes to the
# following interfaces which are only used AFAICT internally:
#
# HTTPProxyConnection
# HTTPSProxyConnection
# Server
#
# Finally, the (internal) logic calling the Transport() interface is
# expected to set the value of the user_agent field in this manner:
#
# transport = Transport()
# transport.user_agent = "foo"
#
# This mechanism thus automatically carries over to all classes
# derived from Transport(), including:
#
# SafeProxyTransport(),
# ProxyTransport()
# SafeTransport()
#
# This patch is provided as is, with no warranty.
#
# Bob Drzyzgula
# redhat at drzyzgula.org
#
diff -r -U 3 rhnlib-1.3.orig/rhn/connections.py rhnlib-1.3.patched/rhn/connections.py
--- rhnlib-1.3.orig/rhn/connections.py 2003-09-03 10:17:06.000000000 -0400
+++ rhnlib-1.3.patched/rhn/connections.py 2004-03-11 13:37:22.000000000 -0500
@@ -115,7 +115,7 @@
class HTTPProxyConnection(HTTPConnection):
- def __init__(self, proxy, host, port=None, username=None, password=None):
+ def __init__(self, proxy, host, port=None, username=None, password=None, proxyHeaders=None):
# The connection goes through the proxy
HTTPConnection.__init__(self, proxy)
# save the proxy values
@@ -127,6 +127,7 @@
# Authenticated proxies support
self.__username = username
self.__password = password
+ self.__headers = proxyHeaders
def connect(self):
# We are actually connecting to the proxy
@@ -145,6 +146,7 @@
HTTPConnection.putrequest(self, method, newurl, skip_host=skip_host)
# Add proxy-specific headers
self._add_auth_proxy_header()
+ self._add_extra_proxy_headers()
def _add_auth_proxy_header(self):
if not self.__username:
@@ -155,6 +157,12 @@
enc_userpass = string.strip(base64.encodestring(userpass))
self.putheader("Proxy-Authorization", "Basic %s" % enc_userpass)
+ def _add_extra_proxy_headers(self):
+ if not self.__headers:
+ return
+ for keywd in self.__headers.keys():
+ self.putheader(keywd,self.__headers[keywd])
+
class HTTPSConnection(HTTPConnection):
response_class = HTTPResponse
default_port = httplib.HTTPSConnection.default_port
@@ -181,8 +189,8 @@
default_port = HTTPSConnection.default_port
def __init__(self, proxy, host, port=None, username=None, password=None,
- trusted_certs = None):
- HTTPProxyConnection.__init__(self, proxy, host, port, username, password)
+ trusted_certs = None, proxyHeaders=None):
+ HTTPProxyConnection.__init__(self, proxy, host, port, username, password, proxyHeaders)
trusted_certs = trusted_certs or []
self.trusted_certs = trusted_certs
@@ -194,6 +202,7 @@
HTTPConnection.putrequest(self, "CONNECT", host)
# Add proxy-specific stuff
self._add_auth_proxy_header()
+ self._add_extra_proxy_headers()
# And send the request
HTTPConnection.endheaders(self)
# Save the response class
diff -r -U 3 rhnlib-1.3.orig/rhn/rpclib.py rhnlib-1.3.patched/rhn/rpclib.py
--- rhnlib-1.3.orig/rhn/rpclib.py 2003-09-04 20:30:38.000000000 -0400
+++ rhnlib-1.3.patched/rhn/rpclib.py 2004-03-17 10:59:47.000000000 -0500
@@ -100,6 +100,7 @@
proxy: use an HTTP proxy
username: username for authenticated HTTP proxy
password: password for authenticated HTTP proxy
+ userAgent: string to use as User Agent String on HTTP connections
All 8-bit strings passed to the server proxy are assumed to use
the given encoding.
@@ -107,7 +108,7 @@
def __init__(self, uri, transport=None, encoding=None, verbose=0,
proxy=None, username=None, password=None, refreshCallback=None,
- progressCallback=None):
+ progressCallback=None,userAgent=None):
# establish a "logical" server connection
#
@@ -136,6 +137,7 @@
self._proxy = proxy
self._username = username
self._password = password
+ self._userAgent = userAgent
# get the url
import urllib
@@ -151,6 +153,8 @@
if transport is None:
self._allow_redirect = 1
transport = self.default_transport(type, proxy, username, password)
+ if userAgent is not None:
+ transport.user_agent = userAgent
else:
#
# dont allow redirect on unknow transports, that should be
@@ -442,14 +446,15 @@
class GETServer(Server):
def __init__(self, uri, transport=None, proxy=None, username=None,
password=None, client_version=2, headers={}, refreshCallback=None,
- progressCallback=None):
+ progressCallback=None,userAgent=None):
Server.__init__(self, uri,
proxy=proxy,
username=username,
password=password,
transport=transport,
refreshCallback=refreshCallback,
- progressCallback=progressCallback)
+ progressCallback=progressCallback,
+ userAgent=userAgent)
self._client_version = client_version
self._headers = headers
# Back up the original handler, since we mangle it
diff -r -U 3 rhnlib-1.3.orig/rhn/transports.py rhnlib-1.3.patched/rhn/transports.py
--- rhnlib-1.3.orig/rhn/transports.py 2003-09-03 10:14:45.000000000 -0400
+++ rhnlib-1.3.patched/rhn/transports.py 2004-03-11 13:40:18.000000000 -0500
@@ -269,7 +269,7 @@
print "Connecting via http to %s proxy %s, username %s, pass %s" % (
host, self._proxy, self._proxy_username, self._proxy_password)
return connections.HTTPProxyConnection(self._proxy, host,
- username=self._proxy_username, password=self._proxy_password)
+ username=self._proxy_username, password=self._proxy_password, proxyHeaders={'User-Agent' : self.user_agent})
class SafeProxyTransport(ProxyTransport):
def __init__(self, proxy, proxyUsername=None, proxyPassword=None,
@@ -294,7 +294,7 @@
print "Connecting via https to %s proxy %s, username %s, pass %s" % (
host, self._proxy, self._proxy_username, self._proxy_password)
return connections.HTTPSProxyConnection(self._proxy, host,
- username=self._proxy_username, password=self._proxy_password,
+ username=self._proxy_username, password=self._proxy_password, proxyHeaders={'User-Agent' : self.user_agent},
trusted_certs=self.trusted_certs)
# ============================================================================
More information about the rhn-users
mailing list