MCPcopy Create free account
hub / github.com/kataras/iris / CheckIfModifiedSince

Method CheckIfModifiedSince

context/context.go:3470–3488  ·  view source on GitHub ↗

CheckIfModifiedSince checks if the response is modified since the "modtime". Note that it has nothing to do with server-side caching. It does those checks by checking if the "If-Modified-Since" request header sent by client or a previous server response header (e.g with WriteWithExpiration or Handle

(modtime time.Time)

Source from the content-addressed store, hash-verified

3468//
3469// It's mostly used internally, e.g. `context#WriteWithExpiration`.
3470func (ctx *Context) CheckIfModifiedSince(modtime time.Time) (bool, error) {
3471 if method := ctx.Method(); method != http.MethodGet && method != http.MethodHead {
3472 return false, fmt.Errorf("method: %w", ErrPreconditionFailed)
3473 }
3474 ims := ctx.GetHeader(IfModifiedSinceHeaderKey)
3475 if ims == "" || IsZeroTime(modtime) {
3476 return false, fmt.Errorf("zero time: %w", ErrPreconditionFailed)
3477 }
3478 t, err := ParseTime(ctx, ims)
3479 if err != nil {
3480 return false, err
3481 }
3482 // sub-second precision, so
3483 // use mtime < t+1s instead of mtime <= t to check for unmodified.
3484 if modtime.UTC().Before(t.Add(1 * time.Second)) {
3485 return false, nil
3486 }
3487 return true, nil
3488}
3489
3490// WriteNotModified sends a 304 "Not Modified" status code to the client,
3491// it makes sure that the content type, the content length headers

Callers 3

WriteWithExpirationMethod · 0.95
browser.goFile · 0.80
FileServerFunction · 0.80

Calls 6

MethodMethod · 0.95
GetHeaderMethod · 0.95
IsZeroTimeFunction · 0.85
ErrorfMethod · 0.80
BeforeMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected