-
I have a simple config with vless client. I'm trying to send raw HTTP request via core.Dial, but conn.Read blocks and returns EOF error. Why? Here is the code: package main
import (
"context"
"fmt"
"log"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/core"
)
func main() {
var xrayInstance *core.Instance
// Initialize xray core here...
dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", "tcp", "api.ipify.org:80"))
if err != nil {
log.Fatal(err)
}
conn, err := core.Dial(context.Background(), xrayInstance, dest)
if err != nil {
log.Fatal(err)
}
_, err = conn.Write([]byte("GET /?format=json HTTP/1.1\n> Host: api.ipify.org\n> User-Agent: curl/8.7.1\n> Accept: */*\\r\\n\\r\\n"))
if err != nil {
log.Fatal(err)
}
fmt.Println("Reading from conn...")
buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil {
log.Fatal(err)
}
fmt.Println("Response:", string(buf[:n]))
} What I get: Reading from conn...
2024/12/10 20:14:30 [Info] app/dispatcher: default route for tcp:api.ipify.org:80
2024/12/10 20:14:30 [Info] transport/internet/tcp: dialing TCP to tcp:[MY_XRAY_SRV_IP]:[PORT]
2024/12/10 20:14:30 [Debug] transport/internet: dialing to tcp:[MY_XRAY_SRV_IP]:[PORT]
2024/12/10 20:14:30 [Info] proxy/vless/outbound: tunneling request to tcp:api.ipify.org:80 via [MY_XRAY_SRV_IP]:[PORT]
2024/12/10 20:14:45 EOF The configuration is correct, because sending HTTP requests via Go's http package works: client := &http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", network, addr))
if err != nil {
return nil, err
}
return core.Dial(ctx, xray, dest)
},
},
} |
Beta Was this translation helpful? Give feedback.
Answered by
godstanis
Dec 11, 2024
Replies: 1 comment
-
Was a stupid mistake on my side. Fix: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
godstanis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was a stupid mistake on my side. Fix:
\\r\\n\\r\\n
->\r\n\r\n