mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 07:26:24 -05:00
fix http error test
This commit is contained in:
parent
a8aab30e6b
commit
2f3670f60b
@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
@ -16,7 +17,6 @@ import (
|
|||||||
"v2ray.com/core/app/proxyman"
|
"v2ray.com/core/app/proxyman"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
"v2ray.com/core/proxy/blackhole"
|
|
||||||
"v2ray.com/core/proxy/freedom"
|
"v2ray.com/core/proxy/freedom"
|
||||||
v2http "v2ray.com/core/proxy/http"
|
v2http "v2ray.com/core/proxy/http"
|
||||||
v2httptest "v2ray.com/core/testing/servers/http"
|
v2httptest "v2ray.com/core/testing/servers/http"
|
||||||
@ -84,6 +84,19 @@ func TestHttpConformance(t *testing.T) {
|
|||||||
func TestHttpError(t *testing.T) {
|
func TestHttpError(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
|
tcpServer := tcp.Server{
|
||||||
|
MsgProcessor: func(msg []byte) []byte {
|
||||||
|
return []byte{}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
dest, err := tcpServer.Start()
|
||||||
|
assert(err, IsNil)
|
||||||
|
defer tcpServer.Close()
|
||||||
|
|
||||||
|
time.AfterFunc(time.Second*2, func() {
|
||||||
|
tcpServer.ShouldClose = true
|
||||||
|
})
|
||||||
|
|
||||||
serverPort := tcp.PickPort()
|
serverPort := tcp.PickPort()
|
||||||
serverConfig := &core.Config{
|
serverConfig := &core.Config{
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
Inbound: []*core.InboundHandlerConfig{
|
||||||
@ -97,7 +110,7 @@ func TestHttpError(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&blackhole.Config{}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -116,7 +129,7 @@ func TestHttpError(t *testing.T) {
|
|||||||
Transport: transport,
|
Transport: transport,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Get("http://127.0.0.1:80")
|
resp, err := client.Get("http://127.0.0.1:" + dest.Port.String())
|
||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
assert(resp.StatusCode, Equals, 503)
|
assert(resp.StatusCode, Equals, 503)
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
Port net.Port
|
Port net.Port
|
||||||
MsgProcessor func(msg []byte) []byte
|
MsgProcessor func(msg []byte) []byte
|
||||||
|
ShouldClose bool
|
||||||
SendFirst []byte
|
SendFirst []byte
|
||||||
Listen net.Address
|
Listen net.Address
|
||||||
listener *net.TCPListener
|
listener *net.TCPListener
|
||||||
@ -65,6 +66,9 @@ func (server *Server) handleConnection(conn net.Conn) {
|
|||||||
fmt.Println("Failed to write response:", err)
|
fmt.Println("Failed to write response:", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if server.ShouldClose {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user