You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2012/04/13 16:20:09 UTC
svn commit: r1325781 - /thrift/trunk/lib/py/src/transport/THttpClient.py
Author: roger
Date: Fri Apr 13 14:20:08 2012
New Revision: 1325781
URL: http://svn.apache.org/viewvc?rev=1325781&view=rev
Log:
THRIFT-1568 Thrift: Add User-Agent header to Python THttpClient
Patch: Dave Watson
Modified:
thrift/trunk/lib/py/src/transport/THttpClient.py
Modified: thrift/trunk/lib/py/src/transport/THttpClient.py
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/py/src/transport/THttpClient.py?rev=1325781&r1=1325780&r2=1325781&view=diff
==============================================================================
--- thrift/trunk/lib/py/src/transport/THttpClient.py (original)
+++ thrift/trunk/lib/py/src/transport/THttpClient.py Fri Apr 13 14:20:08 2012
@@ -18,7 +18,10 @@
#
import httplib
+import os
import socket
+import sys
+import urllib
import urlparse
import warnings
@@ -122,6 +125,13 @@ class THttpClient(TTransportBase):
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)