I’m following the example here to cache files but it seems there’s an issue with If-None-Match. When having it and without request options, the server always return 400 bad request. I guess the If-None-Match header is duplicated.
local function get_http_request_headers(name)
local data = load_http_response_headers(name)
local headers = {}
for k, v in pairs(data) do
if string.lower(k) == 'etag' then
headers['If-None-Match'] = v
elseif string.lower(k) == 'last-modified' then
headers['If-Modified-Since'] = v
end
end
return headers
end
I’m using Nginx for serving files and it rejects requests having duplicate headers.
When adding either Host or If-None-Match to headers, it causes error 400 bad request. It doesn’t happen when I send with options {ignore_cache = true}.
After checking game.project Network section, I see there’s Http Cache Enabled set as default. I think it does something with etag, so causing duplicate header.
You’re right. I knew we had some ETag handling but forgot about the details. The HTTP client will automatically handle ETags in it’s cache and send a If-None-Match request header which explains the duplicate:
So it seems like you are doing duplicate work of handling the ETag also in your client code?
Side-note: We have this feature request to add more cache control options:
I didn’t realize it until I found my app couldn’t load new updates because of the nginx error 400. In testing environment I don’t use nginx so couldn’t see this issue. Also I actually didn’t know that Defold has etag cache handling by default. So my suggestion is that either warn users about this duplication or just handle to discard/merge this header in case users add it
Yeah, we can perhaps handle it in the http_client code. We should at least better document which headers that we set. Could you please create a ticket on GitHub for this issue? Thanks!