2024-07-11 07:56:20 +00:00
|
|
|
package splithttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
gonet "net"
|
|
|
|
|
|
|
|
"github.com/xtls/xray-core/transport/internet/browser_dialer"
|
|
|
|
"github.com/xtls/xray-core/transport/internet/websocket"
|
|
|
|
)
|
|
|
|
|
|
|
|
// implements splithttp.DialerClient in terms of browser dialer
|
|
|
|
// has no fields because everything is global state :O)
|
|
|
|
type BrowserDialerClient struct{}
|
|
|
|
|
2024-12-15 05:43:10 +00:00
|
|
|
func (c *BrowserDialerClient) IsClosed() bool {
|
|
|
|
panic("not implemented yet")
|
|
|
|
}
|
|
|
|
|
2024-11-27 20:19:18 +00:00
|
|
|
func (c *BrowserDialerClient) Open(ctx context.Context, pureURL string) (io.WriteCloser, io.ReadCloser) {
|
|
|
|
panic("not implemented yet")
|
|
|
|
}
|
|
|
|
|
2024-11-09 11:05:41 +00:00
|
|
|
func (c *BrowserDialerClient) OpenUpload(ctx context.Context, baseURL string) io.WriteCloser {
|
|
|
|
panic("not implemented yet")
|
|
|
|
}
|
|
|
|
|
2024-07-11 07:56:20 +00:00
|
|
|
func (c *BrowserDialerClient) OpenDownload(ctx context.Context, baseURL string) (io.ReadCloser, gonet.Addr, gonet.Addr, error) {
|
|
|
|
conn, err := browser_dialer.DialGet(baseURL)
|
|
|
|
dummyAddr := &gonet.IPAddr{}
|
|
|
|
if err != nil {
|
|
|
|
return nil, dummyAddr, dummyAddr, err
|
|
|
|
}
|
|
|
|
|
2024-11-29 02:08:08 +00:00
|
|
|
return websocket.NewConnection(conn, dummyAddr, nil, 0), conn.RemoteAddr(), conn.LocalAddr(), nil
|
2024-07-11 07:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *BrowserDialerClient) SendUploadRequest(ctx context.Context, url string, payload io.ReadWriteCloser, contentLength int64) error {
|
2024-12-11 01:37:05 +00:00
|
|
|
bytes, err := io.ReadAll(payload)
|
2024-07-11 07:56:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = browser_dialer.DialPost(url, bytes)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|