Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
XHTTP client: Add "fakegrpc-up" mode
  • Loading branch information
RPRX authored Nov 20, 2024
commit afc6ce64946aac0eefff3f7f78a68f308170cfc3
2 changes: 1 addition & 1 deletion infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
switch c.Mode {
case "":
c.Mode = "auto"
case "auto", "packet-up", "stream-up":
case "auto", "packet-up", "stream-up", "fakegrpc-up":
default:
return nil, errors.New("unsupported mode: " + c.Mode)
}
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/splithttp/browser_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// has no fields because everything is global state :O)
type BrowserDialerClient struct{}

func (c *BrowserDialerClient) OpenUpload(ctx context.Context, baseURL string) io.WriteCloser {
func (c *BrowserDialerClient) OpenUpload(ctx context.Context, baseURL, mode string) io.WriteCloser {
panic("not implemented yet")
}

Expand Down
9 changes: 6 additions & 3 deletions transport/internet/splithttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type DialerClient interface {
// baseURL already contains sessionId
OpenDownload(context.Context, string) (io.ReadCloser, net.Addr, net.Addr, error)

// (ctx, baseURL) -> uploadWriter
// (ctx, baseURL, mode) -> uploadWriter
// baseURL already contains sessionId
OpenUpload(context.Context, string) io.WriteCloser
OpenUpload(context.Context, string, string) io.WriteCloser
}

// implements splithttp.DialerClient in terms of direct network connections
Expand All @@ -42,10 +42,13 @@ type DefaultDialerClient struct {
dialUploadConn func(ctxInner context.Context) (net.Conn, error)
}

func (c *DefaultDialerClient) OpenUpload(ctx context.Context, baseURL string) io.WriteCloser {
func (c *DefaultDialerClient) OpenUpload(ctx context.Context, baseURL, mode string) io.WriteCloser {
reader, writer := io.Pipe()
req, _ := http.NewRequestWithContext(ctx, "POST", baseURL, reader)
req.Header = c.transportConfig.GetRequestHeader()
if mode == "fakegrpc-up" {
req.Header.Add("Content-Type", "application/grpc")
}
go c.client.Do(req)
return writer
}
Expand Down
12 changes: 8 additions & 4 deletions transport/internet/splithttp/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,15 @@ 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" {
if tlsConfig == nil && realityConfig == nil {
mode = "packet-up"
} else {
mode = "fakegrpc-up"
}
}
if mode == "stream-up" {
conn.writer = httpClient.OpenUpload(ctx, requestURL.String())
if mode != "packet-up" {
conn.writer = httpClient.OpenUpload(ctx, requestURL.String(), mode)
return stat.Connection(&conn), nil
}

Expand Down