nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.19k stars 246 forks source link

If-modified-since and If-none-match headers may break Nuxt when using axios #557

Open fago opened 2 years ago

fago commented 2 years ago

By default nuxt-axios is proxying headers when doing requests. This is a very handy feature but becomes dangerous when If-modified-since or If-none-match headers are present.

We had the severe issue of google search console reporting repeated 503 errors, but those were not reproducable. After logs of investigation we were able to determine what happened via the logs: Sometime the google bot sent a "if-modified-since" header, what gets proxied, so the backend correctly responded with an (empty) 304 response. Axios by default handles 304 status as ok and tries to process the response as normal. Since it's empty it fails and errors out with error 500.

Unfortunately, nuxt cannot handle 304 responses since it does not have the cached previous response. Instead, axios should not forward the If-modified-since and If-none-match headers (since axios does not have the cache, that would be correct).

We were able to fix this by add the headers to https://axios.nuxtjs.org/options#proxyheadersignore - unfortunately one has to repeat all the other headers being ignored by the default when settings this option. That's not ideal for maintenance (as this shows, this is a critical setting to have correct), but that's a different issue.

Long story short, I think proxying If-modified-since and If-none-match headers does not make sense in general and those should be included by default in https://axios.nuxtjs.org/options#proxyheadersignore

davision commented 2 years ago

Any news on resolving PR for this issue?