THRIFT-1568 Thrift: Add User-Agent header to Python THttpClient
Patch: Dave Watson
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1325781 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/transport/THttpClient.py b/lib/py/src/transport/THttpClient.py
index 293d930..ea80a1a 100644
--- a/lib/py/src/transport/THttpClient.py
+++ b/lib/py/src/transport/THttpClient.py
@@ -18,7 +18,10 @@
#
import httplib
+import os
import socket
+import sys
+import urllib
import urlparse
import warnings
@@ -122,6 +125,13 @@
self.__http.putheader('Content-Type', 'application/x-thrift')
self.__http.putheader('Content-Length', str(len(data)))
+ if not self.__custom_headers or 'User-Agent' not in self.__custom_headers:
+ user_agent = 'Python/THttpClient'
+ script = os.path.basename(sys.argv[0])
+ if script:
+ user_agent = '%s (%s)' % (user_agent, urllib.quote(script))
+ self.__http.putheader('User-Agent', user_agent)
+
if self.__custom_headers:
for key, val in self.__custom_headers.iteritems():
self.__http.putheader(key, val)