handle source IP for PNG queries (#311)
This commit is contained in:
parent
e7b7b91277
commit
a17e778bca
2 changed files with 8 additions and 3 deletions
|
|
@ -55,7 +55,11 @@ def client_ip_address(request):
|
||||||
Flask related
|
Flask related
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if request.headers.getlist("X-Forwarded-For"):
|
if request.headers.getlist("X-PNG-Query-For"):
|
||||||
|
ip_addr = request.headers.getlist("X-PNG-Query-For")[0]
|
||||||
|
if ip_addr.startswith('::ffff:'):
|
||||||
|
ip_addr = ip_addr[7:]
|
||||||
|
elif request.headers.getlist("X-Forwarded-For"):
|
||||||
ip_addr = request.headers.getlist("X-Forwarded-For")[0]
|
ip_addr = request.headers.getlist("X-Forwarded-For")[0]
|
||||||
if ip_addr.startswith('::ffff:'):
|
if ip_addr.startswith('::ffff:'):
|
||||||
ip_addr = ip_addr[7:]
|
ip_addr = ip_addr[7:]
|
||||||
|
|
@ -238,6 +242,7 @@ def wttr(location, request):
|
||||||
|
|
||||||
if png_filename:
|
if png_filename:
|
||||||
options = {
|
options = {
|
||||||
|
'ip_addr': ip_addr,
|
||||||
'lang': lang,
|
'lang': lang,
|
||||||
'location': location}
|
'location': location}
|
||||||
options.update(query)
|
options.update(query)
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,6 @@ def make_wttr_in_png(png_name, options=None):
|
||||||
if key not in parsed:
|
if key not in parsed:
|
||||||
parsed[key] = val
|
parsed[key] = val
|
||||||
url = make_wttrin_query(parsed)
|
url = make_wttrin_query(parsed)
|
||||||
print("URL = ", url)
|
|
||||||
|
|
||||||
timestamp = time.strftime("%Y%m%d%H", time.localtime())
|
timestamp = time.strftime("%Y%m%d%H", time.localtime())
|
||||||
cached_basename = url[14:].replace('/','_')
|
cached_basename = url[14:].replace('/','_')
|
||||||
|
|
@ -315,7 +314,8 @@ def make_wttr_in_png(png_name, options=None):
|
||||||
if os.path.exists(cached_png_file):
|
if os.path.exists(cached_png_file):
|
||||||
return cached_png_file
|
return cached_png_file
|
||||||
|
|
||||||
text = requests.get(url).text.replace('\n', '\r\n')
|
headers = {'X-PNG-Query-For': options.get('ip_addr', '1.1.1.1')}
|
||||||
|
text = requests.get(url, headers=headers).text.replace('\n', '\r\n')
|
||||||
curl_output = text.encode('utf-8')
|
curl_output = text.encode('utf-8')
|
||||||
|
|
||||||
typescript_to_one_frame(cached_png_file, curl_output, options=parsed)
|
typescript_to_one_frame(cached_png_file, curl_output, options=parsed)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue