Description
What version of Go are you using (go version
)?
$ go version 1.20.2 darwin/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/beaubrueggemann/Library/Caches/go-build" GOENV="/Users/beaubrueggemann/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/beaubrueggemann/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/beaubrueggemann/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.19.4" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" 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/47/c0lsmsxn3_z86w657l519d6m0000gn/T/go-build1135191649=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
I updated Go from version 1.19.4 to version 1.20.2 and ran my server.
Here's an abbreviated version of the source, that shows the problem:
package main import ( "log" "net/http" ) const ( PostPath = "/postpage.html" PostName = "name" ) var FileServer = http.FileServer(http.Dir("/site")) func MyHandler(w http.ResponseWriter, r *http.Request) { if r.URL.Path == PostPath { // Handle post data. value := r.PostFormValue(PostName) // Server does something with value here... log.Println(value) } // Serve page from filesystem FileServer.ServeHTTP(w, r) } func main() { log.Fatal(http.ListenAndServe(":8080", http.HandlerFunc(MyHandler))) }
Then I tried a POST request to the "localhost:8080/postpage.html" URL.
What did you expect to see?
I expected to receive a status 200, served with a body matching the file on my filesystem at /site/postpage.html
What did you see instead?
I received a 405 status (method not allowed), with a body consisting of "read-only"
I dug into the problem, and it results from commit 413554.
This change breaks the compatibility promise. I was surprised there was no discussion of compatibility in the commit review or the corresponding issue (53501).
It is useful to be able to wrap an http.FileServer with an http.Handler that handles POST data, etc., then forwards to http.FileServer to serve a static response body. But now this doesn't work anymore.