Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3492

DefaultHttpHeaders does not handle last-modified and if-modified-since requests correctly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.8.1
    • Fix Version/s: 2.3.12
    • Component/s: Plugin - REST
    • Labels:
      None

      Description

      1. Create a controller method that creates a DefaultHttpHeaders object, then calls lastModified(...).withNoETag()
      2. Hit the method in a browser; verify that the response contains a "Last-Modified" header and no "ETag" header
      3. Refresh the browser
      4. Verify that the browser request contains an "If-Modified-Since" header with the same date
      5. Look at the http response code

      What happens?
      The controller returns a 200 OK instead of a 304 Not Modified, so the browser can't use its cache.

      DefaultHttpHeaders has code (DefaultHttpHeaders.java ln 132) that tries to determine whether the last modified date matches the "If-Modified-Since" header. However, it does so by making a string comparison between the header string ("Tue Sep 07 16:34:08 PDT 2010") and a number of milliseconds ("112345..."), which is going to fail.

      I worked around this by adding custom code to the controller that compares lastModified and If-Modified-Since, and calls withStatus(HttpServletResponse.SC_NOT_MODIFIED) if appropriate, but it would be cleaner if DefaultHttpHeaders handled this automatically (as it is obviously trying to do).

        Attachments

          Activity

            People

            • Assignee:
              lukaszlenart Lukasz Lenart
              Reporter:
              gcmcnaughton Gordon McNaughton
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: