1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 15:36:41 -05:00

add support for header based early data on server side

This commit is contained in:
Shelikhoo 2021-05-01 01:31:41 +01:00
parent 54d0c3d400
commit 75231604c7
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -27,6 +27,7 @@ type requestHandler struct {
path string
ln *Listener
earlyDataEnabled bool
earlyDataHeaderName string
}
var upgrader = &websocket.Upgrader{
@ -45,6 +46,13 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
writer.WriteHeader(http.StatusNotFound)
return
}
} else if h.earlyDataHeaderName != "" {
if request.URL.Path != h.path {
writer.WriteHeader(http.StatusNotFound)
return
}
earlyDataStr := request.Header.Get(h.earlyDataHeaderName)
earlyData = base64.NewDecoder(base64.RawURLEncoding, bytes.NewReader([]byte(earlyDataStr)))
} else {
if strings.HasPrefix(request.URL.RequestURI(), h.path) {
earlyDataStr := request.URL.RequestURI()[len(h.path):]
@ -135,8 +143,10 @@ func ListenWS(ctx context.Context, address net.Address, port net.Port, streamSet
l.listener = listener
var useEarlyData = false
var earlyDataHeaderName = ""
if wsSettings.MaxEarlyData != 0 {
useEarlyData = true
earlyDataHeaderName = wsSettings.EarlyDataHeaderName
}
l.server = http.Server{
@ -144,9 +154,10 @@ func ListenWS(ctx context.Context, address net.Address, port net.Port, streamSet
path: wsSettings.GetNormalizedPath(),
ln: l,
earlyDataEnabled: useEarlyData,
earlyDataHeaderName: earlyDataHeaderName,
},
ReadHeaderTimeout: time.Second * 4,
MaxHeaderBytes: 2048,
MaxHeaderBytes: http.DefaultMaxHeaderBytes,
}
go func() {