On Fri, Jan 16, 2009 at 04:12:19PM +0100, Tilman Baumann wrote:
> Untested code:
> 
>   import httplib
>   conn = httplib.HTTPConnection("tile.openstreetmap.org")
>   conn.request("HEAD", "/file...")
>   r1 = conn.getresponse()
>   print r1.status, r1.reason
>   etag = getheader("ETag")
>   print etag
> 
> And if stuff was new, make GET instead of HEAD

   The 'If-None-Match:' header field of the GET request appears to do the
right thing. 

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26

   Example using wget when we don't have the tile:

$ wget --server-response http://tile.openstreetmap.org/5/6/7.png
--2009-01-22 18:14:19--  http://tile.openstreetmap.org/5/6/7.png
Løser tile.openstreetmap.org...128.40.58.204
Connecting to tile.openstreetmap.org|128.40.58.204|:80... forbundet.
HTTP forespørgsel sendt, afventer svar... 
  HTTP/1.1 200 OK
  Date: Thu, 22 Jan 2009 17:14:19 GMT
  Server: Apache/2.2.4 (Ubuntu)
  ETag: "865cd3d3cc1cf8ae3cf920234f539d91"
  Content-Length: 5822
  Cache-Control: max-age=518361
  Expires: Wed, 28 Jan 2009 17:13:40 GMT
  Keep-Alive: timeout=3, max=100
  Connection: Keep-Alive
  Content-Type: image/png
Længde: 5822 (5,7K) [image/png]
Saving to: `7.png'

2009-01-22 18:14:19 (179 KB/s) - `7.png' saved [5822/5822]

   Example where we have an up-to-date tile already:

$ wget --server-response \
--header 'If-None-Match: "865cd3d3cc1cf8ae3cf920234f539d91"' \
http://tile.openstreetmap.org/5/6/7.png
--2009-01-22 18:15:25--  http://tile.openstreetmap.org/5/6/7.png
Løser tile.openstreetmap.org...128.40.58.204
Connecting to tile.openstreetmap.org|128.40.58.204|:80... forbundet.
HTTP forespørgsel sendt, afventer svar... 
  HTTP/1.1 304 Not Modified
  Date: Thu, 22 Jan 2009 17:15:25 GMT
  Server: Apache/2.2.4 (Ubuntu)
  Connection: Keep-Alive
  Keep-Alive: timeout=3, max=100
  ETag: "865cd3d3cc1cf8ae3cf920234f539d91"
  Expires: Wed, 28 Jan 2009 18:17:50 GMT
  Cache-Control: max-age=522144
2009-01-22 18:15:25 FEJL 304: Not Modified.

   Example where we have an outdated tile:

$ wget --server-response \
--header 'If-None-Match: "865cd3d3cc1cf8ae3cf920234f539d90"' \
http://tile.openstreetmap.org/5/6/7.png
--2009-01-22 18:23:10--  http://tile.openstreetmap.org/5/6/7.png
Løser tile.openstreetmap.org...128.40.58.204
Connecting to tile.openstreetmap.org|128.40.58.204|:80... forbundet.
HTTP forespørgsel sendt, afventer svar... 
  HTTP/1.1 200 OK
  Date: Thu, 22 Jan 2009 17:23:10 GMT
  Server: Apache/2.2.4 (Ubuntu)
  ETag: "865cd3d3cc1cf8ae3cf920234f539d91"
  Content-Length: 5822
  Cache-Control: max-age=522491
  Expires: Wed, 28 Jan 2009 18:31:22 GMT
  Keep-Alive: timeout=3, max=100
  Connection: Keep-Alive
  Content-Type: image/png
Længde: 5822 (5,7K) [image/png]
Saving to: `7.png'

2009-01-22 18:23:10 (129 KB/s) - `7.png' saved [5822/5822]


-- 
Rask Ingemann Lambertsen
Danish law requires addresses in e-mail to be logged and stored for a year

_______________________________________________
Openmoko community mailing list
community@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/community

Reply via email to