http.FileServer caching files and serving old versions after edit

后端 未结 4 1872
甜味超标
甜味超标 2020-12-31 11:51

Having issues with the http package in the core of go. It appears that the file contents is cached although the Content-Length in the response body is correct. To demonstrat

相关标签:
4条回答
  • 2020-12-31 11:53

    Until VirtualBox has fixed the issue I made a go file that can be dropped into a project to disable sendfile support for the current process, go http package will then fallback to io.Copy. Also works with boot2docker with some small docker config changes.

    https://github.com/wader/disable_sendfile_vbox_linux

    With newer versions of firejail you can do the same thing using:

    firejail --seccomp.enotsup=sendfile ./program
    
    0 讨论(0)
  • 2020-12-31 12:03

    If you use some kind of an proxy, that would be the problem. Some proxies cache frequently used files (usually only .js, .css etc., but usually not .html) and ip addresses. If the server is on your local computer, try to use localhost or 127.0.0.1 instead of an ip address, so the request doesn't go trough the proxy. If it's not you have to configure or disable the proxy to access the newest version of the website. I don't know how common this is but, it would be the problem.

    0 讨论(0)
  • 2020-12-31 12:06

    This can be a client issue, what browser are you using ? Maybe you could try different browsers, curl, wget etc...

    0 讨论(0)
  • 2020-12-31 12:09

    Ok, so after a few weeks of ignoring the problem and moving on I have finally worked out what the issue is.

    In order to leave my main computer fairly uncustomised I use Vagrant to develop applications using golang, nodejs and php. It appears that running a go application on a Virtual Box share with all the html files stored on that share causes this issue.

    To prove this I span up a Vagrant box and copied the files from the /vagrant shared directory to /home/vagrant/testing/, then replicated all the previously listed actions. This made the problem disappear.

    So in other words, don't use a Virtual Box shared folder to host files intended for use in a http.FileServer method.

    0 讨论(0)
提交回复
热议问题