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
This commit is contained in:
Roger Meier 2012-04-13 14:20:08 +00:00
parent a3410db0c8
commit 3f5a264cd9

View File

@ -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)