Skip to content

Commit

Permalink
fix: check if resources was modified using etag only if available
Browse files Browse the repository at this point in the history
  • Loading branch information
p3k committed Jan 4, 2020
1 parent cff8f98 commit 0316500
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion roxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from gzip import compress, decompress
from io import StringIO
from sys import exc_info
from wsgiref.handlers import format_date_time

from urllib.error import HTTPError
from urllib.request import Request, urlopen
Expand Down Expand Up @@ -113,7 +114,11 @@ def set_header(header_name, value):

set_header('Accept', request.headers.get('Accept'))
set_header('Cookie', urlencode(request.cookies) or None)
set_header('If-None-Match', resource['headers'].get('etag'))
set_header('If-Modified-Since', format_date_time(resource['date'].timestamp()))

etag = resource['headers'].get('ETag')
if etag: set_header('If-None-Match', etag)

set_header('Referer', request.referrer)

response = get_url(url, headers)
Expand Down

0 comments on commit 0316500

Please sign in to comment.