Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mp_tile.py: use If-Modified-Since to try to reuse tile data #1458

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions MAVProxy/modules/mavproxy_map/mp_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import math
import threading
import os
import pathlib
import string
import time
import cv2
Expand Down Expand Up @@ -284,11 +285,28 @@ def downloader(self):
print("Downloading %s [%u left]" % (url, len(keys)))
req = url_request(url)
req.add_header('User-Agent', 'MAVProxy')

# try to re-use our cached data:
try:
mtime = os.path.getmtime(path)
req.add_header('If-Modified-Since', time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(mtime)))
except Exception:
pass

if url.find('google') != -1:
req.add_header('Referer', 'https://maps.google.com/')
resp = url_open(req)
headers = resp.info()
except url_error as e:
try:
if e.getcode() == 304:
# cache hit; touch the file to reset its refresh time
pathlib.Path(path).touch()
self._download_pending.pop(key)
continue
except Exception as ex:
pass

#print('Error loading %s' % url)
if not key in self._tile_cache:
self._tile_cache[key] = self._unavailable
Expand Down