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
Add wroteRequest (not supported by quic-go)
  • Loading branch information
RPRX authored Dec 11, 2024
commit 3f23afcbd7b888b3571be1c46c97b29e9b9e2a98
2 changes: 1 addition & 1 deletion transport/internet/splithttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (c *DefaultDialerClient) OpenDownload(ctx context.Context, baseURL string)
}

func (c *DefaultDialerClient) SendUploadRequest(ctx context.Context, url string, payload io.ReadWriteCloser, contentLength int64) error {
req, err := http.NewRequest("POST", url, payload)
req, err := http.NewRequestWithContext(ctx, "POST", url, payload)
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions transport/internet/splithttp/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
gotls "crypto/tls"
"io"
"net/http"
"net/http/httptrace"
"net/url"
"strconv"
"sync"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/signal/done"
"github.com/xtls/xray-core/common/signal/semaphore"
"github.com/xtls/xray-core/common/uuid"
"github.com/xtls/xray-core/transport/internet"
Expand Down Expand Up @@ -405,7 +407,10 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
seq := requestCounter
requestCounter += 1

wroteRequest := done.New()

go func() {
defer wroteRequest.Close()
defer requestsLimiter.Signal()

// this intentionally makes a shallow-copy of the struct so we
Expand All @@ -415,6 +420,12 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
// reassign query to get different padding
url.RawQuery = transportConfiguration.GetNormalizedQuery()

ctx := httptrace.WithClientTrace(ctx, &httptrace.ClientTrace{
WroteRequest: func(httptrace.WroteRequestInfo) {
wroteRequest.Close()
},
})

err := httpClient.SendUploadRequest(
context.WithoutCancel(ctx),
url.String(),
Expand All @@ -435,6 +446,10 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me

lastWrite = time.Now()
}

if _, ok := httpClient.(*DefaultDialerClient); ok {
<-wroteRequest.Wait()
}
}
}()

Expand Down
Loading