mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-08 14:13:22 +00:00
Browser Dialer: Fix WSS with no early data
Fixes https://github.com/2dust/v2rayNG/issues/5519#issuecomment-4357741914
This commit is contained in:
@@ -20,10 +20,10 @@ import (
|
|||||||
var webpage []byte
|
var webpage []byte
|
||||||
|
|
||||||
type task struct {
|
type task struct {
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Extra any `json:"extra,omitempty"`
|
Extra any `json:"extra,omitempty"`
|
||||||
StreamResponse bool `json:"streamResponse"`
|
StreamResponse bool `json:"streamResponse"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var conns chan *websocket.Conn
|
var conns chan *websocket.Conn
|
||||||
@@ -51,9 +51,9 @@ func Reload() {
|
|||||||
if HasBrowserDialer() {
|
if HasBrowserDialer() {
|
||||||
for len(conns) > 0 {
|
for len(conns) > 0 {
|
||||||
select {
|
select {
|
||||||
case c := <-conns:
|
case c := <-conns:
|
||||||
c.Close()
|
c.Close()
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conns = nil
|
conns = nil
|
||||||
@@ -75,7 +75,7 @@ func Reload() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*");
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Write(webpage)
|
w.Write(webpage)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -94,15 +94,13 @@ type webSocketExtra struct {
|
|||||||
|
|
||||||
func DialWS(uri string, ed []byte) (*websocket.Conn, error) {
|
func DialWS(uri string, ed []byte) (*websocket.Conn, error) {
|
||||||
task := task{
|
task := task{
|
||||||
Method: "WS",
|
Method: "WS",
|
||||||
URL: uri,
|
URL: uri,
|
||||||
StreamResponse: true,
|
StreamResponse: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ed != nil {
|
task.Extra = webSocketExtra{
|
||||||
task.Extra = webSocketExtra{
|
Protocol: base64.RawURLEncoding.EncodeToString(ed),
|
||||||
Protocol: base64.RawURLEncoding.EncodeToString(ed),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dialTask(task)
|
return dialTask(task)
|
||||||
@@ -144,9 +142,9 @@ func httpExtraFromHeadersAndCookies(headers http.Header, cookies []*http.Cookie)
|
|||||||
|
|
||||||
func DialGet(uri string, headers http.Header, cookies []*http.Cookie) (*websocket.Conn, error) {
|
func DialGet(uri string, headers http.Header, cookies []*http.Cookie) (*websocket.Conn, error) {
|
||||||
task := task{
|
task := task{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
URL: uri,
|
URL: uri,
|
||||||
Extra: httpExtraFromHeadersAndCookies(headers, cookies),
|
Extra: httpExtraFromHeadersAndCookies(headers, cookies),
|
||||||
StreamResponse: true,
|
StreamResponse: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,9 +157,9 @@ func DialPacket(method string, uri string, headers http.Header, cookies []*http.
|
|||||||
|
|
||||||
func dialWithBody(method string, uri string, headers http.Header, cookies []*http.Cookie, payload []byte) error {
|
func dialWithBody(method string, uri string, headers http.Header, cookies []*http.Cookie, payload []byte) error {
|
||||||
task := task{
|
task := task{
|
||||||
Method: method,
|
Method: method,
|
||||||
URL: uri,
|
URL: uri,
|
||||||
Extra: httpExtraFromHeadersAndCookies(headers, cookies),
|
Extra: httpExtraFromHeadersAndCookies(headers, cookies),
|
||||||
StreamResponse: false,
|
StreamResponse: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,4 +220,3 @@ func CheckOK(conn *websocket.Conn) error {
|
|||||||
func init() {
|
func init() {
|
||||||
Reload()
|
Reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user