Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: ServeContent add Cache-Control header #47539

Open
mhewedy opened this issue Aug 4, 2021 · 2 comments
Open

net/http: ServeContent add Cache-Control header #47539

mhewedy opened this issue Aug 4, 2021 · 2 comments

Comments

@mhewedy
Copy link

@mhewedy mhewedy commented Aug 4, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.5 darwin/amd64

Does this issue reproduce with the latest release?

I don't know

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mhewedy/Library/Caches/go-build"
GOENV="/Users/mhewedy/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mhewedy/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mhewedy/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.5/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_m/6fmdhfh952d1kvxm2h85c2rm0000gn/T/go-build4269072314=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

calling http.ServeContent to serve file from the server, it doesn't send "Cache-Control" header at all, and even the source code fs.go doesn't mention it.

What did you expect to see?

According to retrofit (the famous Android HTTP client), it needs to see Cache-Control with value must-revalidate on the response header so it can send the HTTP request with "if-modified-since" HTTP request header. and hence http.ServeContent doesn't send such a header, then the resources are kept in Retrofit cache forever.

What did you see instead?

http.ServeContent doesn't send "Cache-Control" response header at all.

@seankhliao seankhliao changed the title http.ServeContent doesn't send cache-control by default net/http: ServeContent add Cache-Control header Aug 7, 2021
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Aug 7, 2021

cc @neild

@neild
Copy link
Contributor

@neild neild commented Aug 8, 2021

Given that there isn't a universally correct Cache-Control value, not setting one by default and leaving it up to the user to it if desired seems like the best approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants