support header override in websocket

pull/642/merge
Darien Raymond 2017-10-13 23:54:04 +08:00
parent 476d67f494
commit 669a0cafaf
4 changed files with 59 additions and 28 deletions

View File

@ -1,6 +1,8 @@
package websocket package websocket
import ( import (
"net/http"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"
) )
@ -16,6 +18,14 @@ func (c *Config) GetNormailzedPath() string {
return path return path
} }
func (c *Config) GetRequestHeader() http.Header {
header := http.Header{}
for _, h := range c.Header {
header.Add(h.Key, h.Value)
}
return header
}
func init() { func init() {
common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_WebSocket, func() interface{} { common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_WebSocket, func() interface{} {
return new(Config) return new(Config)

View File

@ -15,25 +15,34 @@ var _ = math.Inf
// proto package needs to be updated. // proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type ConnectionReuse struct { type Header struct {
Enable bool `protobuf:"varint,1,opt,name=enable" json:"enable,omitempty"` Key string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
Value string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
} }
func (m *ConnectionReuse) Reset() { *m = ConnectionReuse{} } func (m *Header) Reset() { *m = Header{} }
func (m *ConnectionReuse) String() string { return proto.CompactTextString(m) } func (m *Header) String() string { return proto.CompactTextString(m) }
func (*ConnectionReuse) ProtoMessage() {} func (*Header) ProtoMessage() {}
func (*ConnectionReuse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } func (*Header) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *ConnectionReuse) GetEnable() bool { func (m *Header) GetKey() string {
if m != nil { if m != nil {
return m.Enable return m.Key
} }
return false return ""
}
func (m *Header) GetValue() string {
if m != nil {
return m.Value
}
return ""
} }
type Config struct { type Config struct {
// URL path to the WebSocket service. Empty value means root(/). // URL path to the WebSocket service. Empty value means root(/).
Path string `protobuf:"bytes,2,opt,name=path" json:"path,omitempty"` Path string `protobuf:"bytes,2,opt,name=path" json:"path,omitempty"`
Header []*Header `protobuf:"bytes,3,rep,name=header" json:"header,omitempty"`
} }
func (m *Config) Reset() { *m = Config{} } func (m *Config) Reset() { *m = Config{} }
@ -48,8 +57,15 @@ func (m *Config) GetPath() string {
return "" return ""
} }
func (m *Config) GetHeader() []*Header {
if m != nil {
return m.Header
}
return nil
}
func init() { func init() {
proto.RegisterType((*ConnectionReuse)(nil), "v2ray.core.transport.internet.websocket.ConnectionReuse") proto.RegisterType((*Header)(nil), "v2ray.core.transport.internet.websocket.Header")
proto.RegisterType((*Config)(nil), "v2ray.core.transport.internet.websocket.Config") proto.RegisterType((*Config)(nil), "v2ray.core.transport.internet.websocket.Config")
} }
@ -58,18 +74,20 @@ func init() {
} }
var fileDescriptor0 = []byte{ var fileDescriptor0 = []byte{
// 204 bytes of a gzipped FileDescriptorProto // 229 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0xcf, 0x31, 0x4b, 0xc7, 0x30, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xb2, 0x28, 0x33, 0x2a, 0x4a,
0x10, 0x05, 0x70, 0x52, 0xfe, 0x94, 0x36, 0x8b, 0x92, 0x41, 0x3a, 0x96, 0x2e, 0xad, 0x08, 0x09, 0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x29, 0x4a, 0xcc, 0x2b,
0xd4, 0xc5, 0xd9, 0x4e, 0x3a, 0x49, 0x10, 0x05, 0xb7, 0x34, 0x9e, 0x5a, 0xb4, 0x77, 0x25, 0x3d, 0x2e, 0xc8, 0x2f, 0x2a, 0xd1, 0xcf, 0xcc, 0x2b, 0x49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0xd8, 0x2a, 0x21, 0x21, 0x2e, 0x96, 0x82, 0xc4, 0x92, 0x0c, 0xa8, 0x34, 0x98, 0x2d, 0xe4,
0x7e, 0xab, 0xb2, 0x5a, 0x74, 0xa5, 0xdd, 0xef, 0xdb, 0x43, 0x21, 0x4e, 0xb3, 0xeb, 0x67, 0x79, 0xce, 0xc5, 0x96, 0x01, 0x36, 0x4f, 0x82, 0x59, 0x81, 0x59, 0x83, 0xdb, 0x48, 0x5f, 0x8f, 0x48,
0xe1, 0x69, 0xd6, 0x47, 0xb6, 0xdf, 0x89, 0xa7, 0x32, 0x85, 0x9f, 0xac, 0x7d, 0xe8, 0xad, 0xdb, 0x97, 0xe8, 0x41, 0x9c, 0x11, 0x04, 0xd5, 0xee, 0xc5, 0xc2, 0xc1, 0x28, 0xc0, 0xe4, 0x94, 0xc2,
0xf4, 0xf0, 0xc7, 0xee, 0x13, 0xbb, 0x89, 0xec, 0x31, 0x7e, 0x8e, 0xf9, 0x3e, 0xf2, 0xf2, 0x37, 0xa5, 0x9d, 0x9c, 0x9f, 0x4b, 0xac, 0x19, 0x01, 0x8c, 0x51, 0x9c, 0x70, 0xce, 0x2a, 0x26, 0xf5,
0x00, 0x00, 0xff, 0xff, 0x7a, 0xf3, 0x2b, 0x77, 0x20, 0x01, 0x00, 0x00, 0x30, 0xa3, 0xa0, 0xc4, 0x4a, 0x3d, 0x67, 0x90, 0xb6, 0x10, 0xb8, 0x36, 0x4f, 0x98, 0xb6, 0x70,
0x98, 0xca, 0x24, 0x36, 0x70, 0xa0, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xf5, 0x7e, 0x60,
0xf9, 0x70, 0x01, 0x00, 0x00,
} }

View File

@ -6,8 +6,9 @@ option go_package = "websocket";
option java_package = "com.v2ray.core.transport.internet.websocket"; option java_package = "com.v2ray.core.transport.internet.websocket";
option java_multiple_files = true; option java_multiple_files = true;
message ConnectionReuse { message Header {
bool enable = 1; string key = 1;
string value = 2;
} }
message Config { message Config {
@ -15,4 +16,6 @@ message Config {
// URL path to the WebSocket service. Empty value means root(/). // URL path to the WebSocket service. Empty value means root(/).
string path = 2; string path = 2;
repeated Header header = 3;
} }

View File

@ -59,7 +59,7 @@ func dialWebsocket(ctx context.Context, dest net.Destination) (net.Conn, error)
} }
uri := protocol + "://" + host + wsSettings.GetNormailzedPath() uri := protocol + "://" + host + wsSettings.GetNormailzedPath()
conn, resp, err := dialer.Dial(uri, nil) conn, resp, err := dialer.Dial(uri, wsSettings.GetRequestHeader())
if err != nil { if err != nil {
var reason string var reason string
if resp != nil { if resp != nil {