XHTTP XMUX: Abandon client if client.Do(req) failed (#4253)

51769fdde1
This commit is contained in:
RPRX 2025-01-06 14:06:11 +00:00 committed by GitHub
parent aeb12d9e3b
commit ce6c0dc690
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 14 deletions

View file

@ -1,6 +1,7 @@
package splithttp
import (
"bytes"
"context"
"crypto/tls"
"io"
@ -102,6 +103,12 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
h.config.WriteResponseHeader(writer)
clientVer := []int{0, 0, 0}
x_version := strings.Split(request.URL.Query().Get("x_version"), ".")
for j := 0; j < 3 && len(x_version) > j; j++ {
clientVer[j], _ = strconv.Atoi(x_version[j])
}
validRange := h.config.GetNormalizedXPaddingBytes()
x_padding := int32(len(request.URL.Query().Get("x_padding")))
if validRange.To > 0 && (x_padding < validRange.From || x_padding > validRange.To) {
@ -160,6 +167,13 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
writer.WriteHeader(http.StatusConflict)
} else {
writer.WriteHeader(http.StatusOK)
if request.ProtoMajor != 1 && len(clientVer) > 0 && clientVer[0] >= 25 {
paddingLen := h.config.GetNormalizedXPaddingBytes().rand()
if paddingLen > 0 {
writer.Write(bytes.Repeat([]byte{'0'}, int(paddingLen)))
}
writer.(http.Flusher).Flush()
}
<-request.Context().Done()
}
return