Skip to content

Commit

Permalink
Merge branch 'XTLS:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
omengye authored Nov 22, 2024
2 parents c15c090 + 513f18b commit 61df3b3
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 38 deletions.
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var (
Version_x byte = 24
Version_y byte = 11
Version_z byte = 11
Version_z byte = 21
)

var (
Expand Down
2 changes: 2 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ type SplitHTTPConfig struct {
DownloadSettings *StreamConfig `json:"downloadSettings"`
Mode string `json:"mode"`
Extra json.RawMessage `json:"extra"`
NoGRPCHeader bool `json:"noGRPCHeader"`
}

type Xmux struct {
Expand Down Expand Up @@ -322,6 +323,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
XPaddingBytes: splithttpNewRandRangeConfig(c.XPaddingBytes),
Xmux: &muxProtobuf,
Mode: c.Mode,
NoGRPCHeader: c.NoGRPCHeader,
}
var err error
if c.DownloadSettings != nil {
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func (c *Config) getHosts() []string {
if len(c.Host) == 0 {
return []string{"www.example.com"}
return []string{""}
}
return c.Host
}
Expand Down
9 changes: 8 additions & 1 deletion transport/internet/http/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,16 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
}
}

Host := httpSettings.getRandomHost()
if Host == "" && net.ParseAddress(dest.NetAddr()).Family().IsDomain() {
Host = dest.Address.String()
} else if Host == "" {
Host = "www.example.com"
}

request := &http.Request{
Method: httpMethod,
Host: httpSettings.getRandomHost(),
Host: Host,
Body: breader,
URL: &url.URL{
Scheme: "https",
Expand Down
3 changes: 3 additions & 0 deletions transport/internet/splithttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (c *DefaultDialerClient) OpenUpload(ctx context.Context, baseURL string) io
reader, writer := io.Pipe()
req, _ := http.NewRequestWithContext(ctx, "POST", baseURL, reader)
req.Header = c.transportConfig.GetRequestHeader()
if !c.transportConfig.NoGRPCHeader {
req.Header.Set("Content-Type", "application/grpc")
}
go c.client.Do(req)
return writer
}
Expand Down
77 changes: 44 additions & 33 deletions transport/internet/splithttp/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions transport/internet/splithttp/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ message Config {
Multiplexing xmux = 9;
xray.transport.internet.StreamConfig downloadSettings = 10;
string mode = 11;
bool noGRPCHeader = 12;
}

message RandRangeConfig {
Expand Down
8 changes: 6 additions & 2 deletions transport/internet/splithttp/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,13 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
}

mode := transportConfiguration.Mode
if mode == "auto" && realityConfig != nil {
mode = "stream-up"
if mode == "auto" {
mode = "packet-up"
if (tlsConfig != nil && len(tlsConfig.NextProtocol) != 1) || realityConfig != nil {
mode = "stream-up"
}
}
errors.LogInfo(ctx, "XHTTP is using mode: "+mode)
if mode == "stream-up" {
conn.writer = httpClient.OpenUpload(ctx, requestURL.String())
return stat.Connection(&conn), nil
Expand Down

0 comments on commit 61df3b3

Please sign in to comment.