What version of Go are you using (go version
)?
Support for HTTP OPTIONS Method in New String Pattern Matching for Handle and HandleFunc
$ go version go version go1.23.0 darwin/amd64
Does this issue reproduce with the latest release?
Issue introduced in go version 1.22 https://go.dev/blog/routing-enhancements and still reproduce with the latest release
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/Users/example/Library/Caches/go-build' GOENV='/Users/example/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/example/go/pkg/mod' GOOS='darwin' GOPATH='/Users/example/go' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/local/Cellar/go/1.23.0/libexec' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/local/Cellar/go/1.23.0/libexec/pkg/tool/darwin_amd64' GOVCS='' GOVERSION='go1.23.0' GODEBUG='' GOTELEMETRY='local' GOTELEMETRYDIR='/Users/example/Library/Application Support/go/telemetry' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='cc' CXX='c++' CGO_ENABLED='1' GOMOD='/Users/example/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/37/2js67n8d49sbrr84_8qc7pxm0000gn/T/go-build2994275656=/tmp/go-build -gno-record-gcc-switches -fno-common' GOROOT/bin/go version: go version go1.23.0 darwin/amd64 GOROOT/bin/go tool compile -V: compile version go1.23.0 uname -v: Darwin Kernel Version 23.2.0: Wed Nov 15 21:54:10 PST 2023; root:xnu-10002.61.3~2/RELEASE_X86_64 ProductName: macOS ProductVersion: 14.2.1 BuildVersion: 23C71 lldb --version: lldb-1500.0.200.58 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
What did you do?
- I created an HTTP server using the standard library.
- I implemented route handling with the new string pattern matching feature.
- I expected the new feature to handle requests using the HTTP OPTIONS method, but it did not handle my use case.
What did you expect to see?
HTTP Methods GET, POST, PUT, DELETE all match a special case OPTIONS just as GET also matches HEAD
What did you see instead?
When I made a request with the HTTP OPTIONS method to the route, the server responded with an HTTP 404 Not Found error instead of processing the request as expected.
Comment From: gabyhelp
Related Issues and Documentation
- net/http: add Server.OptionsHandler to allow custom handling of OPTIONS * #41773 (closed)
- net/http: Conflicts with pattern when using NewServeMux #68838 (closed)
- net/http: request.Method is wrong when path start by // #29584 (closed)
- enhanced routing does not work on linux/debian12 #65746 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: coker-felix
@gabyhelp Thanks