If-none-match header not always set in netlify function

I have noticed that the Etag seems to be stripped from some requests to netlify functions. To be more precise the event argument in my function doesn’t seem to always have a ‘if-none-match’ header even if the client sends a Etag.

Example with Etag (output from console.log(JSON.stringify(event))):

    {
    "path": "/.netlify/functions/service-request-all",
    "httpMethod": "GET",
    "headers": {
        "accept": "*/*",
        "accept-encoding": "br, gzip",
        "accept-language": "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7",
        "client-ip": "213.126.48.18",
        "dnt": "1",
        "if-none-match": "\"-1038293291-df\"",
        "referer": "https://deploy-preview-4--aviva-pwa-poc-service-requests.netlify.com/overview",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36",
        "via": "https/2 Netlify[e3fa7145-efb7-48e2-9bf3-e772b2d6709e] (ApacheTrafficServer/7.1.8)",
        "x-bb-ab": "0.402314",
        "x-bb-client-request-uuid": "e3fa7145-efb7-48e2-9bf3-e772b2d6709e-3162385",
        "x-bb-ip": "213.126.48.18",
        "x-bb-loop": "1",
        "x-country": "NL",
        "x-forwarded-for": "213.126.48.18",
        "x-forwarded-proto": "https",
        "x-language": "nl,nl;q=0.9,en,en;q=0.7",
        "x-nf-client-connection-ip": "213.126.48.18"
    },
    "queryStringParameters": {},
    "body": "",
    "isBase64Encoded": true
}

Example without Etag:
    {
    "path": "/.netlify/functions/service-request-all",
    "httpMethod": "GET",
    "headers": {
        "accept": "*/*",
        "accept-encoding": "br, gzip",
        "accept-language": "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7",
        "client-ip": "213.126.48.18",
        "dnt": "1",     
        "referer": "https://deploy-preview-4--aviva-pwa-poc-service-requests.netlify.com/overview",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36",
        "via": "https/2 Netlify[e3fa7145-efb7-48e2-9bf3-e772b2d6709e] (ApacheTrafficServer/7.1.8)",
        "x-bb-ab": "0.827624",
        "x-bb-client-request-uuid": "e3fa7145-efb7-48e2-9bf3-e772b2d6709e-3165233",
        "x-bb-ip": "213.126.48.18",
        "x-bb-loop": "1",
        "x-country": "NL",
        "x-forwarded-for": "213.126.48.18",
        "x-forwarded-proto": "https",
        "x-language": "nl,nl;q=0.9,en,en;q=0.7",
        "x-nf-client-connection-ip": "213.126.48.18"
    },
    "queryStringParameters": {},
    "body": "",
    "isBase64Encoded": true
}

I need this value so I can skip some expensive queries to a database and return a 304 with a empty body if the etag matches.

When testing this locally with netlify dev this works without problems. This seems like a bug to me unless there is a good reason this happens.

First, the redirect engine used in netlify dev is not necessarily identical with the one we use in production. That said, are you using a redirect proxy (Rewrites and proxies | Netlify Docs)? I I think it’s possible your etag will not match since we use that header internally as well. Even without proxying, that might still happen.