mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-22 12:43:58 +08:00
rewrite request body
This commit is contained in:
parent
feac4b0bef
commit
ebd589ce9c
|
@ -403,8 +403,10 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
|
|||
// websocket over http2, assuming backend doesn't support this, the request will be modifided to http1.1 upgrade
|
||||
// TODO: once we can reliably detect backend support this, it can be removed for those backends
|
||||
if r.ProtoMajor == 2 && r.Method == http.MethodConnect && r.Header.Get(":protocol") != "" {
|
||||
caddyhttp.SetVar(clonedReq.Context(), "h2_websocket", true)
|
||||
clonedReq.Header.Del(":protocol")
|
||||
// keep the body for later use. http1.1 upgrade uses http.NoBody
|
||||
caddyhttp.SetVar(clonedReq.Context(), "h2_websocket_body", clonedReq.Body)
|
||||
clonedReq.Body = http.NoBody
|
||||
clonedReq.Method = http.MethodGet
|
||||
clonedReq.Header.Set("Upgrade", r.Header.Get(":protocol"))
|
||||
clonedReq.Header.Set("Connection", "Upgrade")
|
||||
|
|
|
@ -88,7 +88,8 @@ func (h *Handler) handleUpgradeResponse(logger *zap.Logger, wg *sync.WaitGroup,
|
|||
)
|
||||
// websocket over http2, assuming backend doesn't support this, the request will be modifided to http1.1 upgrade
|
||||
// TODO: once we can reliably detect backend support this, it can be removed for those backends
|
||||
if b, ok := caddyhttp.GetVar(req.Context(), "h2_websocket").(bool); ok && b {
|
||||
if body, ok := caddyhttp.GetVar(req.Context(), "h2_websocket_body").(io.ReadCloser); ok {
|
||||
req.Body = body
|
||||
rw.Header().Del("Upgrade")
|
||||
rw.Header().Del("Connection")
|
||||
rw.Header().Del("Sec-Websocket-Accept")
|
||||
|
|
Loading…
Reference in New Issue
Block a user