[enh] useragent forwarding

This commit is contained in:
asciimoo 2013-10-14 23:52:58 +02:00
parent aa3d63159e
commit 492e0b74c0

View file

@ -38,18 +38,21 @@ def index():
query = request.form['q'] query = request.form['q']
requests = [] requests = []
results = [] results = []
user_agent = request.headers.get('User-Agent', '')
for engine in engines: for engine in engines:
request_params = engine.request(query, default_request_params()) headers = default_request_params()
headers['User-Agent'] = user_agent
request_params = engine.request(query, headers)
callback = make_callback(results, engine.response) callback = make_callback(results, engine.response)
if request_params['method'] == 'GET': if request_params['method'] == 'GET':
req = grequests.get(request_params['url'] req = grequests.get(request_params['url']
,headers=request_params['headers'] ,headers=headers
,hooks=dict(response=callback) ,hooks=dict(response=callback)
) )
else: else:
req = grequests.post(request_params['url'] req = grequests.post(request_params['url']
,data=request_params['data'] ,data=request_params['data']
,headers=request_params['headers'] ,headers=headers
,hooks=dict(response=callback) ,hooks=dict(response=callback)
) )
requests.append(req) requests.append(req)