Merge pull request #97 from parkrrr/feature-http-headers

Feature http headers
This commit is contained in:
Ryan Hitchman 2014-01-20 16:57:25 -08:00
commit 36518e9f91
2 changed files with 10 additions and 12 deletions

View File

@ -9,7 +9,7 @@ def urban(inp):
'''.u/.urban <phrase> -- looks up <phrase> on urbandictionary.com'''
url = 'http://www.urbandictionary.com/iphone/search/define'
page = http.get_json(url, term=inp, referer="http://m.urbandictionary.com")
page = http.get_json(url, term=inp, headers={'Referer': 'http://m.urbandictionary.com'})
defs = page['list']
if page['result_type'] == 'no_results':

View File

@ -42,15 +42,11 @@ def get_json(*args, **kwargs):
return json.loads(get(*args, **kwargs))
def open(url, query_params=None, user_agent=None, referer=None, post_data=None,
get_method=None, cookies=False, oauth=False, oauth_keys=None, **kwargs):
def open(url, query_params=None, post_data=None,
get_method=None, cookies=False, oauth=False, oauth_keys=None, headers=None, **kwargs):
if query_params is None:
query_params = {}
if user_agent is None:
user_agent = ua_skybot
query_params.update(kwargs)
url = prepare_url(url, query_params)
@ -60,10 +56,12 @@ def open(url, query_params=None, user_agent=None, referer=None, post_data=None,
if get_method is not None:
request.get_method = lambda: get_method
request.add_header('User-Agent', user_agent)
if headers is not None:
for header_key, header_value in headers.iteritems():
request.add_header(header_key, header_value)
if referer is not None:
request.add_header('Referer', referer)
if 'User-Agent' not in request.headers:
request.add_header('User-Agent', ua_skybot)
if oauth:
nonce = oauth_nonce()