responseheaders.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. .. _gwc_responseheaders:
  2. HTTP Response Headers
  3. =====================
  4. The GeoWebCache integrated with GeoServer employs special information stored in the header of responses. These headers are available either with direct calls to the :ref:`GeoWebCache endpoint <gwc_endpoint>` or with :ref:`direct WMS integration <gwc_directwms>`.
  5. Custom response headers
  6. -----------------------
  7. GeoWebCache returns both standard and custom HTTP response headers when serving a tile request. This aids in the debugging process, as well as adhering to an HTTP 1.1 transfer control mechanism.
  8. The response headers can be determined via a utility such as `cURL <http://curl.haxx.se>`_.
  9. Example
  10. ~~~~~~~
  11. .. note:: For all cURL commands below, make sure to replace ``>/dev/null`` with ``>nul`` if you are running on Windows.
  12. This is a sample request and response using cURL:
  13. .. code-block:: console
  14. curl -v "http://localhost:8080/geoserver/gwc/service/wms?LAYERS=sde%3Abmworld&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A4326&BBOX=-180,-38,-52,90&WIDTH=256&HEIGHT=256&tiled=true" > /dev/null
  15. ::
  16. < HTTP/1.1 200 OK
  17. < geowebcache-tile-index: [0, 1, 2]
  18. < geowebcache-cache-result: HIT
  19. < geowebcache-tile-index: [0, 1, 2]
  20. < geowebcache-tile-bounds: -180.0,-38.0,-52.0,90.0
  21. < geowebcache-gridset: GlobalCRS84Pixel
  22. < geowebcache-crs: EPSG:4326
  23. < Content-Type: image/png
  24. < Content-Length: 102860
  25. < Server: Jetty(6.1.8)
  26. From this, one can learn that the tile was found in the cache (``HIT``), the requested tile was from the gridset called ``GlobalCRS84Pixel`` and had a CRS of ``EPSG:4326``.
  27. List of custom response headers
  28. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. The following is the full list of custom response headers. Whenever GeoWebCache serves a tile request, it will write some or all of the following custom headers on the HTTP response.
  30. .. list-table::
  31. :header-rows: 1
  32. * - Response Header
  33. - Description
  34. * - ``geowebcache-cache-result``
  35. - Shows whether the GeoWebCache WMS was used. Options are:
  36. * ``HIT``: Tile requested was found on the cache
  37. * ``MISS``: Tile was not found on the cache but was acquired from the layer's data source
  38. * ``WMS``: Request was proxied directly to the origin WMS (for example, for GetFeatureInfo requests)
  39. * ``OTHER``: Response was the default white/transparent tile or an error occurred
  40. * - ``geowebcache-tile-index``
  41. - Contains the three-dimensional tile index in x,y,z order of the returned tile image in the corresponding grid space (e.g. ``[1, 0, 0]``)
  42. * - ``geowebcache-tile-bounds``
  43. - Bounds of the returned tile in the corresponding coordinate reference system (e.g. ``-180,-90,0,90``)
  44. * - ``geowebcache-gridset``
  45. - Name of the gridset the tile belongs to (see :ref:`gwc_webadmin_gridsets` for more information)
  46. * - ``geowebcache-crs``
  47. - Coordinate reference system code of the matching gridset (e.g. ``EPSG:900913``, ``EPSG:4326``, etc).
  48. .. _gwc_lastmodifiedheaders:
  49. Last-Modified and If-Modified-Since
  50. -----------------------------------
  51. Well behaved HTTP 1.1 clients and server applications can make use of ``Last-Modified`` and ``If-Modified-Since`` HTTP control mechanisms to know when locally cached content is up to date, eliminating the need to download the same content again. This can result in considerable bandwidth savings. (See HTTP 1.1 `RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>`_, sections 14.29 and 14.25, for more information on these mechanisms.)
  52. GeoWebCache will write a ``Last-Modified`` HTTP response header when serving a tile image. The date is written as an RFC-1123 ``HTTP-Date``::
  53. Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT
  54. Clients connecting to GeoWebCache can create a "conditional GET" request with the ``If-Modified-Since`` request header. If the tile wasn't modified after the date specified in the ``Last-Modified`` response header, GeoWebCache will return a ``304`` status code indicating that the resource was available and not modified.
  55. Example
  56. ~~~~~~~
  57. A query for a specific tile returns the ``Last-Modified`` response header:
  58. .. code-block:: console
  59. curl -v "http://localhost:8080/geoserver/gwc/service/wms?LAYERS=img%20states&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-135,45,-90,90&WIDTH=256&HEIGHT=256" >/dev/null
  60. ::
  61. > Host: localhost:8080
  62. > Accept: */*
  63. >
  64. < HTTP/1.1 200 OK
  65. ...
  66. < Last-Modified: Wed, 25 Jul 2012 00:42:00 GMT
  67. < Content-Type: image/png
  68. < Content-Length: 31192
  69. This request has the ``If-Modified-Since`` header set to one second after what was returned by ``Last-Modified``:
  70. .. code-block:: console
  71. curl --header "If-Modified-Since: Wed, 25 Jul 2012 00:42:01 GMT" -v "http://localhost:8080/geoserver/gwc/service/wms?LAYERS=img%20states&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-135,45,-90,90&WIDTH=256&HEIGHT=256" >/dev/null
  72. ::
  73. > Host: localhost:8080
  74. > Accept: */*
  75. > If-Modified-Since: Wed, 25 Jul 2012 00:42:01 GMT
  76. >
  77. < HTTP/1.1 304 Not Modified
  78. < Last-Modified: Wed, 25 Jul 2012 00:42:00 GMT
  79. < Content-Type: image/png
  80. < Content-Length: 31192
  81. The response code is ``304``. As the file hasn't been modified since the time specified in the request, no content is actually transferred. The client is informed that its copy of the tile is up to date.
  82. However, if you were to set the ``If-Modified-Since`` header to *before* the time stored in ``Last-Modified``, you will instead receive a ``200`` status code and the tile will be downloaded.
  83. This example sets the ``If-Modified-Since`` header to one second before what was returned by ``Last-Modified``:
  84. .. code-block:: console
  85. curl --header "If-Modified-Since: Wed, 25 Jul 2012 00:41:59 GMT" -v "http://localhost:8080/geoserver/gwc/service/wms?LAYERS=img%20states&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-135,45,-90,90&WIDTH=256&HEIGHT=256" >/dev/null
  86. ::
  87. > Host: localhost:8080
  88. > Accept: */*
  89. > If-Modified-Since: Wed, 25 Jul 2012 00:41:59 GMT
  90. >
  91. < HTTP/1.1 200 OK
  92. ...
  93. < Last-Modified: Wed, 25 Jul 2012 00:42:00 GMT
  94. < Content-Type: image/png
  95. < Content-Length: 31192