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:
parent
54d0c3d400
commit
75231604c7
@ -24,9 +24,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type requestHandler struct {
|
type requestHandler struct {
|
||||||
path string
|
path string
|
||||||
ln *Listener
|
ln *Listener
|
||||||
earlyDataEnabled bool
|
earlyDataEnabled bool
|
||||||
|
earlyDataHeaderName string
|
||||||
}
|
}
|
||||||
|
|
||||||
var upgrader = &websocket.Upgrader{
|
var upgrader = &websocket.Upgrader{
|
||||||
@ -45,6 +46,13 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
|
|||||||
writer.WriteHeader(http.StatusNotFound)
|
writer.WriteHeader(http.StatusNotFound)
|
||||||
return
|
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 {
|
} else {
|
||||||
if strings.HasPrefix(request.URL.RequestURI(), h.path) {
|
if strings.HasPrefix(request.URL.RequestURI(), h.path) {
|
||||||
earlyDataStr := request.URL.RequestURI()[len(h.path):]
|
earlyDataStr := request.URL.RequestURI()[len(h.path):]
|
||||||
@ -135,18 +143,21 @@ func ListenWS(ctx context.Context, address net.Address, port net.Port, streamSet
|
|||||||
|
|
||||||
l.listener = listener
|
l.listener = listener
|
||||||
var useEarlyData = false
|
var useEarlyData = false
|
||||||
|
var earlyDataHeaderName = ""
|
||||||
if wsSettings.MaxEarlyData != 0 {
|
if wsSettings.MaxEarlyData != 0 {
|
||||||
useEarlyData = true
|
useEarlyData = true
|
||||||
|
earlyDataHeaderName = wsSettings.EarlyDataHeaderName
|
||||||
}
|
}
|
||||||
|
|
||||||
l.server = http.Server{
|
l.server = http.Server{
|
||||||
Handler: &requestHandler{
|
Handler: &requestHandler{
|
||||||
path: wsSettings.GetNormalizedPath(),
|
path: wsSettings.GetNormalizedPath(),
|
||||||
ln: l,
|
ln: l,
|
||||||
earlyDataEnabled: useEarlyData,
|
earlyDataEnabled: useEarlyData,
|
||||||
|
earlyDataHeaderName: earlyDataHeaderName,
|
||||||
},
|
},
|
||||||
ReadHeaderTimeout: time.Second * 4,
|
ReadHeaderTimeout: time.Second * 4,
|
||||||
MaxHeaderBytes: 2048,
|
MaxHeaderBytes: http.DefaultMaxHeaderBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user