mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/http: clarify panic conditions in Handle, HandleFunc, AddInsecureBypassPattern
Add explicit mention that these methods panic on both pattern conflict
and invalid syntax.
Fixes #75226
Change-Id: If7dbfc44e1ec4624ab156f0e5d7e66cee2c2fef3
GitHub-Last-Rev: acc9a9c333
GitHub-Pull-Request: golang/go#75297
Reviewed-on: https://go-review.googlesource.com/c/go/+/701016
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Mark Freeman <markfreeman@google.com>
This commit is contained in:
parent
b9e2977f1d
commit
aa83aee7de
2 changed files with 12 additions and 4 deletions
|
|
@ -90,6 +90,10 @@ var sentinelHandler Handler = &noopHandler{}
|
||||||
// would redirect to a pattern (e.g. after cleaning the path or adding a
|
// would redirect to a pattern (e.g. after cleaning the path or adding a
|
||||||
// trailing slash) are not.
|
// trailing slash) are not.
|
||||||
//
|
//
|
||||||
|
// AddInsecureBypassPattern panics if the pattern conflicts with one already
|
||||||
|
// registered, or if the pattern is syntactically invalid (for example, an
|
||||||
|
// improperly formed wildcard).
|
||||||
|
//
|
||||||
// AddInsecureBypassPattern can be called concurrently with other methods or
|
// AddInsecureBypassPattern can be called concurrently with other methods or
|
||||||
// request handling, and applies to future requests.
|
// request handling, and applies to future requests.
|
||||||
func (c *CrossOriginProtection) AddInsecureBypassPattern(pattern string) {
|
func (c *CrossOriginProtection) AddInsecureBypassPattern(pattern string) {
|
||||||
|
|
|
||||||
|
|
@ -2868,8 +2868,10 @@ func (mux *ServeMux) ServeHTTP(w ResponseWriter, r *Request) {
|
||||||
// always refers to user code.
|
// always refers to user code.
|
||||||
|
|
||||||
// Handle registers the handler for the given pattern.
|
// Handle registers the handler for the given pattern.
|
||||||
// If the given pattern conflicts with one that is already registered, Handle
|
// If the given pattern conflicts with one that is already registered
|
||||||
// panics.
|
// or if the pattern is invalid, Handle panics.
|
||||||
|
//
|
||||||
|
// See [ServeMux] for details on valid patterns and conflict rules.
|
||||||
func (mux *ServeMux) Handle(pattern string, handler Handler) {
|
func (mux *ServeMux) Handle(pattern string, handler Handler) {
|
||||||
if use121 {
|
if use121 {
|
||||||
mux.mux121.handle(pattern, handler)
|
mux.mux121.handle(pattern, handler)
|
||||||
|
|
@ -2879,8 +2881,10 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleFunc registers the handler function for the given pattern.
|
// HandleFunc registers the handler function for the given pattern.
|
||||||
// If the given pattern conflicts with one that is already registered, HandleFunc
|
// If the given pattern conflicts with one that is already registered
|
||||||
// panics.
|
// or if the pattern is invalid, HandleFunc panics.
|
||||||
|
//
|
||||||
|
// See [ServeMux] for details on valid patterns and conflict rules.
|
||||||
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
|
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
|
||||||
if use121 {
|
if use121 {
|
||||||
mux.mux121.handleFunc(pattern, handler)
|
mux.mux121.handleFunc(pattern, handler)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue