mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
feat: add built-in reverse proxy support
Provide an RFC-aware reverse proxy handler so Touka services can forward normal, streaming, and upgraded HTTP traffic without leaving the framework. Document the new API and proxy-chain behavior so deployments behind other gateways preserve forwarding metadata correctly.
This commit is contained in:
parent
e5400c2da7
commit
764a764720
7 changed files with 1540 additions and 0 deletions
13
respw.go
13
respw.go
|
|
@ -45,6 +45,15 @@ func newResponseWriter(w http.ResponseWriter) ResponseWriter {
|
|||
}
|
||||
}
|
||||
|
||||
// UnwrapResponseWriter returns the underlying stdlib response writer when the
|
||||
// provided writer is Touka's internal wrapper.
|
||||
func UnwrapResponseWriter(w ResponseWriter) http.ResponseWriter {
|
||||
if wrapped, ok := w.(*responseWriterImpl); ok && wrapped.ResponseWriter != nil {
|
||||
return wrapped.ResponseWriter
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
func (rw *responseWriterImpl) reset(w http.ResponseWriter) {
|
||||
rw.ResponseWriter = w
|
||||
rw.status = 0
|
||||
|
|
@ -56,6 +65,10 @@ func (rw *responseWriterImpl) WriteHeader(statusCode int) {
|
|||
if rw.hijacked {
|
||||
return
|
||||
}
|
||||
if statusCode >= 100 && statusCode < 200 && statusCode != http.StatusSwitchingProtocols {
|
||||
rw.ResponseWriter.WriteHeader(statusCode)
|
||||
return
|
||||
}
|
||||
if rw.status == 0 { // 确保只设置一次
|
||||
rw.status = statusCode
|
||||
rw.ResponseWriter.WriteHeader(statusCode)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue