Add v2ray HTTP transport
This commit is contained in:
@@ -8,9 +8,10 @@ import (
|
||||
|
||||
type _V2RayTransportOptions struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
GRPCOptions V2RayGRPCOptions `json:"-"`
|
||||
HTTPOptions V2RayHTTPOptions `json:"-"`
|
||||
WebsocketOptions V2RayWebsocketOptions `json:"-"`
|
||||
QUICOptions V2RayQUICOptions `json:"-"`
|
||||
GRPCOptions V2RayGRPCOptions `json:"-"`
|
||||
}
|
||||
|
||||
type V2RayTransportOptions _V2RayTransportOptions
|
||||
@@ -20,12 +21,14 @@ func (o V2RayTransportOptions) MarshalJSON() ([]byte, error) {
|
||||
switch o.Type {
|
||||
case "":
|
||||
return nil, nil
|
||||
case C.V2RayTransportTypeGRPC:
|
||||
v = o.GRPCOptions
|
||||
case C.V2RayTransportTypeHTTP:
|
||||
v = o.HTTPOptions
|
||||
case C.V2RayTransportTypeWebsocket:
|
||||
v = o.WebsocketOptions
|
||||
case C.V2RayTransportTypeQUIC:
|
||||
v = o.QUICOptions
|
||||
case C.V2RayTransportTypeGRPC:
|
||||
v = o.GRPCOptions
|
||||
default:
|
||||
return nil, E.New("unknown transport type: " + o.Type)
|
||||
}
|
||||
@@ -39,12 +42,14 @@ func (o *V2RayTransportOptions) UnmarshalJSON(bytes []byte) error {
|
||||
}
|
||||
var v any
|
||||
switch o.Type {
|
||||
case C.V2RayTransportTypeGRPC:
|
||||
v = &o.GRPCOptions
|
||||
case C.V2RayTransportTypeHTTP:
|
||||
v = &o.HTTPOptions
|
||||
case C.V2RayTransportTypeWebsocket:
|
||||
v = &o.WebsocketOptions
|
||||
case C.V2RayTransportTypeQUIC:
|
||||
v = &o.QUICOptions
|
||||
case C.V2RayTransportTypeGRPC:
|
||||
v = &o.GRPCOptions
|
||||
default:
|
||||
return E.New("unknown transport type: " + o.Type)
|
||||
}
|
||||
@@ -55,52 +60,11 @@ func (o *V2RayTransportOptions) UnmarshalJSON(bytes []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
/*type _V2RayOutboundTransportOptions struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
GRPCOptions V2RayGRPCOptions `json:"-"`
|
||||
WebsocketOptions V2RayWebsocketOptions `json:"-"`
|
||||
}
|
||||
|
||||
type V2RayOutboundTransportOptions _V2RayOutboundTransportOptions
|
||||
|
||||
func (o V2RayOutboundTransportOptions) MarshalJSON() ([]byte, error) {
|
||||
var v any
|
||||
switch o.Type {
|
||||
case "":
|
||||
return nil, nil
|
||||
case C.V2RayTransportTypeGRPC:
|
||||
v = o.GRPCOptions
|
||||
case C.V2RayTransportTypeWebsocket:
|
||||
v = o.WebsocketOptions
|
||||
default:
|
||||
return nil, E.New("unknown transport type: " + o.Type)
|
||||
}
|
||||
return MarshallObjects((_V2RayOutboundTransportOptions)(o), v)
|
||||
}
|
||||
|
||||
func (o *V2RayOutboundTransportOptions) UnmarshalJSON(bytes []byte) error {
|
||||
err := json.Unmarshal(bytes, (*_V2RayOutboundTransportOptions)(o))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var v any
|
||||
switch o.Type {
|
||||
case C.V2RayTransportTypeGRPC:
|
||||
v = &o.GRPCOptions
|
||||
case C.V2RayTransportTypeWebsocket:
|
||||
v = &o.WebsocketOptions
|
||||
default:
|
||||
return E.New("unknown transport type: " + o.Type)
|
||||
}
|
||||
err = UnmarshallExcluded(bytes, (*_V2RayOutboundTransportOptions)(o), v)
|
||||
if err != nil {
|
||||
return E.Cause(err, "vmess transport options")
|
||||
}
|
||||
return nil
|
||||
}*/
|
||||
|
||||
type V2RayGRPCOptions struct {
|
||||
ServiceName string `json:"service_name,omitempty"`
|
||||
type V2RayHTTPOptions struct {
|
||||
Host Listable[string] `json:"host,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
}
|
||||
|
||||
type V2RayWebsocketOptions struct {
|
||||
@@ -111,3 +75,7 @@ type V2RayWebsocketOptions struct {
|
||||
}
|
||||
|
||||
type V2RayQUICOptions struct{}
|
||||
|
||||
type V2RayGRPCOptions struct {
|
||||
ServiceName string `json:"service_name,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user