Het NGR server host grote bestanden zoals de 1.79 GiB inspireadressen.zip, aka “INSPIRE Download Service van BAG - INSPIRE”. Deze URL support zowel CORS als Range requests, maar niet in combinatie.
Huidige response op HEAD request
curl -I 'https://geodata.nationaalgeoregister.nl/inspireadressen/extract/inspireadressen.zip'
HTTP/1.1 200
Date: Thu, 09 Sep 2021 17:25:03 GMT
Last-Modified: Mon, 09 Aug 2021 06:52:36 GMT
Content-Disposition: attachment; filename=inspireadressen.zip
Content-Range: bytes 0-1931988030/1931988031
Accept-Ranges: bytes
Content-Type: application/x-zip-compressed
Content-Length: 1931988031
X-Cnection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, HEAD
Access-Control-Max-Age: 1000
Access-Control-Allow-Headers: SOAPAction,X-Requested-With,Content-Type,Origin,Authorization,Accept
X-Cnection: close
Voor een CORS request met range wordt een Preflight request uitgevoerd dat er zo uit ziet:
Sample HTTP Preflight Request & Response
OPTIONS /inspireadressen/extract/inspireadressen.zip HTTP/1.1
Host: geodata.nationaalgeoregister.nl
Access-Control-Request-Method: GET
Access-Control-Request-Headers: range
Origin: https://www.example.org
welke een 200 OK
of 204 No Content
terug zou moeten geven:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: range
Sample HTTP CORS Range Request & Response na Preflight
GET /inspireadressen/extract/inspireadressen.zip HTTP/1.1
Host: geodata.nationaalgeoregister.nl
Range: bytes=0-1
Origin: https://www.example.org
met als antwoord:
HTTP/1.1 206 Partial Content
Date: Thu, 09 Sep 2021 17:41:55 GMT
Last-Modified: Mon, 09 Aug 2021 06:52:36 GMT
Content-Disposition: attachment; filename=inspireadressen.zip
Content-Range: bytes 0-1/1931988031
Accept-Ranges: bytes
Content-Type: application/x-zip-compressed
Content-Length: 2
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Access-Control-Expose-Headers: Content-Range, Content-Disposition
PK
Huidige Preflight Request & Response
curl -i 'https://geodata.nationaalgeoregister.nl/inspireadressen/extract/inspireadressen.zip' -X OPTIONS -H 'Access-Control-Request-Method: GET' -H 'Access-Control-Request-Headers: range' -H 'Origin: https://www.example.org'
echter een 403:
HTTP/1.1 403
Date: Thu, 09 Sep 2021 17:45:29 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 0
X-Cnection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, HEAD
Access-Control-Max-Age: 1000
Access-Control-Allow-Headers: SOAPAction,X-Requested-With,Content-Type,Origin,Authorization,Accept
X-Cnection: close
Huidige CORS Range GET Request & Response op de resource
curl -i 'https://geodata.nationaalgeoregister.nl/inspireadressen/extract/inspireadressen.zip' -H 'Range: bytes=0-1' -H 'Origin: https://www.example.org'
In de Response mist Access-Control-Expose-Headers: Content-Range, Content-Disposition
:
HTTP/1.1 206
Date: Thu, 09 Sep 2021 17:47:39 GMT
Last-Modified: Mon, 09 Aug 2021 06:52:36 GMT
Content-Disposition: attachment; filename=inspireadressen.zip
Content-Range: bytes 0-1/1931988031
Accept-Ranges: bytes
Content-Type: application/x-zip-compressed
Content-Length: 2
X-Cnection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, HEAD
Access-Control-Max-Age: 1000
Access-Control-Allow-Headers: SOAPAction,X-Requested-With,Content-Type,Origin,Authorization,Accept
X-Cnection: close
PK
Technische details:
Ik wilde enkel de laatste 22 bytes requesten waar de End Of Central Directory Record (EOCD) staat om daarna alle Central directory entries te downloaden en enkel de 18.35 MiB van 9999WPL08072021.zip
op te halen, ofwel < 19 MiB request i.p.v. > 1.79 GiB. Dit kan allemaal met zip.js (na wat patching).
Demo (met CORS proxy):
Zie CORS Range demo - Broersma (in een paar regels code) welke de inspireadressen.zip Central directory leest en laat zien met behulp van een CORS proxy (https://cors-anywhere.herokuapp.com).