Skip to content

Combination of If-None-Match and If-Modified-Since does not work properly #1

@drsybren

Description

@drsybren

RFC 7232 states:

A recipient MUST ignore If-Modified-Since if the request contains an
If-None-Match header field; the condition in If-None-Match is
considered to be a more accurate replacement for the condition in
If-Modified-Since, and the two are only combined for the sake of
interoperating with older intermediaries that might not implement
If-None-Match.

However, the code in func IsFresh() does not take this into account, and happily returns a 304 Not Modified when the Last-Modified response header does not exceed the If-Modified-Since request header.

In practice this means that this scenario will fail:

  • Download a file, store its metadata.
  • The server restores a backup of the server's files, including the modification dates of the served files.
  • Trying to download the file again will still return a "fresh" status, even when the etag is a mis-match.

I haven't run the unit tests, but this code seems to fix things for me:

	if etag != "" && ifNoneMatch != "" {
		return checkEtagNoneMatch(trimTags(strings.Split(ifNoneMatch, ",")), etag)
	}

	if etag != "" && ifMatch != "" {
		return checkEtagMatch(trimTags(strings.Split(ifMatch, ",")), etag)
	}

	if lastModified != "" && ifModifiedSince != "" {
		return checkModifedMatch(lastModified, ifModifiedSince)
	}

	if lastModified != "" && ifUnmodifiedSince != "" {
		return checkUnmodifedMatch(lastModified, ifUnmodifiedSince)
	}

	return false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions