add a pattern argument to Mux

This commit is contained in:
Patricio Whittingslow
2026-07-26 22:55:50 -03:00
parent e46e45238d
commit 75d2c0c46d
3 changed files with 19 additions and 5 deletions
+8
View File
@@ -38,6 +38,8 @@ type Exchange struct {
hijacked bool
rw conn
matchedPattern string
respRemains int
respErr error // Sticky: response is unrecoverable once a write fails.
headerWritten bool
@@ -97,6 +99,7 @@ func (exch *Exchange) Acquire(conn conn) bool {
if !exch.used.CompareAndSwap(false, true) {
return false
}
exch.matchedPattern = ""
exch.gen.Add(1)
exch.readErr = nil
exch.respErr = nil
@@ -366,6 +369,11 @@ func (exch *Exchange) remainingSurplusBody() ([]byte, error) {
return toRead, nil
}
// MuxPattern returns the pattern [Mux] matched to the request.
func (exch *Exchange) MuxPattern() string {
return exch.matchedPattern
}
// RequestHeaderRaw returns the parsed request header for access beyond the
// Request* methods, such as [httpraw.Header.ForEach]. Valid until the exchange
// is released, and writing to it corrupts the response.