|
@@ -6,6 +6,8 @@ import (
|
|
|
"strings"
|
|
"strings"
|
|
|
"testing"
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
+ "v2ray.com/core/common/net"
|
|
|
|
|
+
|
|
|
. "v2ray.com/core/common/protocol/http"
|
|
. "v2ray.com/core/common/protocol/http"
|
|
|
. "v2ray.com/ext/assert"
|
|
. "v2ray.com/ext/assert"
|
|
|
)
|
|
)
|
|
@@ -53,3 +55,41 @@ Accept-Language: de,en;q=0.7,en-us;q=0.3
|
|
|
assert(req.Header.Get("Proxy-Connection"), IsEmpty)
|
|
assert(req.Header.Get("Proxy-Connection"), IsEmpty)
|
|
|
assert(req.Header.Get("Proxy-Authenticate"), IsEmpty)
|
|
assert(req.Header.Get("Proxy-Authenticate"), IsEmpty)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func TestParseHost(t *testing.T) {
|
|
|
|
|
+ testCases := []struct {
|
|
|
|
|
+ RawHost string
|
|
|
|
|
+ DefaultPort net.Port
|
|
|
|
|
+ Destination net.Destination
|
|
|
|
|
+ Error bool
|
|
|
|
|
+ }{
|
|
|
|
|
+ {
|
|
|
|
|
+ RawHost: "v2ray.com:80",
|
|
|
|
|
+ DefaultPort: 443,
|
|
|
|
|
+ Destination: net.TCPDestination(net.DomainAddress("v2ray.com"), 80),
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ RawHost: "tls.v2ray.com",
|
|
|
|
|
+ DefaultPort: 443,
|
|
|
|
|
+ Destination: net.TCPDestination(net.DomainAddress("tls.v2ray.com"), 443),
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ RawHost: "[2401:1bc0:51f0:ec08::1]:80",
|
|
|
|
|
+ DefaultPort: 443,
|
|
|
|
|
+ Destination: net.TCPDestination(net.ParseAddress("[2401:1bc0:51f0:ec08::1]"), 80),
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, testCase := range testCases {
|
|
|
|
|
+ dest, err := ParseHost(testCase.RawHost, testCase.DefaultPort)
|
|
|
|
|
+ if testCase.Error {
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ t.Error("for test case: ", testCase.RawHost, " expected error, but actually nil")
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if dest != testCase.Destination {
|
|
|
|
|
+ t.Error("for test case: ", testCase.RawHost, " expected host: ", testCase.Destination.String(), " but got ", dest.String())
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|