Compare commits

..

1 Commits

Author SHA1 Message Date
peze c0ff3925e1 add context 2025-07-21 16:30:08 +08:00
8 changed files with 48 additions and 1704 deletions
+17 -53
View File
@@ -94,7 +94,6 @@ type RuntimeObject struct {
IgnoreSSL *bool `json:"ignoreSSL" xml:"ignoreSSL"`
ReadTimeout *int `json:"readTimeout" xml:"readTimeout"`
ConnectTimeout *int `json:"connectTimeout" xml:"connectTimeout"`
IdleTimeout *int `json:"idleTimeout" xml:"idleTimeout"`
LocalAddr *string `json:"localAddr" xml:"localAddr"`
HttpProxy *string `json:"httpProxy" xml:"httpProxy"`
HttpsProxy *string `json:"httpsProxy" xml:"httpsProxy"`
@@ -115,7 +114,7 @@ type RuntimeObject struct {
func (r *RuntimeObject) getClientTag(domain string) string {
return strconv.FormatBool(BoolValue(r.IgnoreSSL)) + strconv.Itoa(IntValue(r.ReadTimeout)) +
strconv.Itoa(IntValue(r.ConnectTimeout)) + strconv.Itoa(IntValue(r.IdleTimeout)) + StringValue(r.LocalAddr) + StringValue(r.HttpProxy) +
strconv.Itoa(IntValue(r.ConnectTimeout)) + StringValue(r.LocalAddr) + StringValue(r.HttpProxy) +
StringValue(r.HttpsProxy) + StringValue(r.NoProxy) + StringValue(r.Socks5Proxy) + StringValue(r.Socks5NetWork) + domain
}
@@ -129,7 +128,6 @@ func NewRuntimeObject(runtime map[string]interface{}) *RuntimeObject {
IgnoreSSL: TransInterfaceToBool(runtime["ignoreSSL"]),
ReadTimeout: TransInterfaceToInt(runtime["readTimeout"]),
ConnectTimeout: TransInterfaceToInt(runtime["connectTimeout"]),
IdleTimeout: TransInterfaceToInt(runtime["idleTimeout"]),
LocalAddr: TransInterfaceToString(runtime["localAddr"]),
HttpProxy: TransInterfaceToString(runtime["httpProxy"]),
HttpsProxy: TransInterfaceToString(runtime["httpsProxy"]),
@@ -186,39 +184,6 @@ func Convert(in interface{}, out interface{}) error {
return err
}
// ConvertChan converts the source data to the target type and sends it to the specified channel.
// @param src - source data
// @param destChan - target channel
// @return error - error during the conversion process
func ConvertChan(src interface{}, destChan interface{}) error {
destChanValue := reflect.ValueOf(destChan)
if destChanValue.Kind() != reflect.Chan {
return fmt.Errorf("destChan must be a channel")
}
if destChanValue.Type().ChanDir() == reflect.SendDir {
return fmt.Errorf("destChan must be a receive or bidirectional channel")
}
elemType := destChanValue.Type().Elem()
destValue := reflect.New(elemType).Interface()
err := Convert(src, destValue)
if err != nil {
return err
}
destValueElem := reflect.ValueOf(destValue).Elem()
defer func() {
if r := recover(); r != nil {
}
}()
destChanValue.TrySend(destValueElem)
return nil
}
// Recover is used to format error
func Recover(in interface{}) error {
if in == nil {
@@ -323,7 +288,7 @@ func DoRequest(request *Request, runtimeObject *RuntimeObject) (response *Respon
if !defaultClient.ifInit || defaultClient.httpClient.Transport == nil {
defaultClient.httpClient.Transport = trans
}
defaultClient.httpClient.Timeout = time.Duration(IntValue(runtimeObject.ConnectTimeout)+IntValue(runtimeObject.ReadTimeout)) * time.Millisecond
defaultClient.httpClient.Timeout = time.Duration(IntValue(runtimeObject.ReadTimeout)) * time.Millisecond
defaultClient.ifInit = true
defaultClient.Unlock()
}
@@ -442,7 +407,7 @@ func DoRequestWithCtx(ctx context.Context, request *Request, runtimeObject *Runt
if !defaultClient.ifInit || defaultClient.httpClient.Transport == nil {
defaultClient.httpClient.Transport = trans
}
defaultClient.httpClient.Timeout = time.Duration(IntValue(runtimeObject.ConnectTimeout)+IntValue(runtimeObject.ReadTimeout)) * time.Millisecond
defaultClient.httpClient.Timeout = time.Duration(IntValue(runtimeObject.ReadTimeout)) * time.Millisecond
defaultClient.ifInit = true
defaultClient.Unlock()
}
@@ -504,7 +469,6 @@ func DoRequestWithCtx(ctx context.Context, request *Request, runtimeObject *Runt
func getHttpTransport(req *Request, runtime *RuntimeObject) (*http.Transport, error) {
trans := new(http.Transport)
trans.ResponseHeaderTimeout = time.Duration(IntValue(runtime.ReadTimeout)) * time.Millisecond
httpProxy, err := getHttpProxy(StringValue(req.Protocol), StringValue(req.Domain), runtime)
if err != nil {
return nil, err
@@ -558,7 +522,7 @@ func getHttpTransport(req *Request, runtime *RuntimeObject) (*http.Transport, er
Password: password,
}
}
dialer, err := proxy.SOCKS5(strings.ToLower(StringValue(runtime.Socks5NetWork)), socks5Proxy.Host, auth,
dialer, err := proxy.SOCKS5(strings.ToLower(StringValue(runtime.Socks5NetWork)), socks5Proxy.String(), auth,
&net.Dialer{
Timeout: time.Duration(IntValue(runtime.ConnectTimeout)) * time.Millisecond,
DualStack: true,
@@ -576,9 +540,6 @@ func getHttpTransport(req *Request, runtime *RuntimeObject) (*http.Transport, er
trans.MaxIdleConns = IntValue(runtime.MaxIdleConns)
trans.MaxIdleConnsPerHost = IntValue(runtime.MaxIdleConns)
}
if runtime.IdleTimeout != nil && *runtime.IdleTimeout > 0 {
trans.IdleConnTimeout = time.Duration(IntValue(runtime.IdleTimeout)) * time.Millisecond
}
return trans, nil
}
@@ -697,7 +658,7 @@ func getSocks5Proxy(runtime *RuntimeObject) (proxy *url.URL, err error) {
func getLocalAddr(localAddr string) (addr *net.TCPAddr) {
if localAddr != "" {
addr = &net.TCPAddr{
IP: net.ParseIP(localAddr),
IP: []byte(localAddr),
}
}
return addr
@@ -705,17 +666,20 @@ func getLocalAddr(localAddr string) (addr *net.TCPAddr) {
func setDialContext(runtime *RuntimeObject) func(cxt context.Context, net, addr string) (c net.Conn, err error) {
return func(ctx context.Context, network, address string) (net.Conn, error) {
timeout := time.Duration(IntValue(runtime.ConnectTimeout)) * time.Millisecond
dialer := &net.Dialer{
Timeout: timeout,
Resolver: &net.Resolver{
PreferGo: false,
},
}
if runtime.LocalAddr != nil && StringValue(runtime.LocalAddr) != "" {
dialer.LocalAddr = getLocalAddr(StringValue(runtime.LocalAddr))
netAddr := &net.TCPAddr{
IP: []byte(StringValue(runtime.LocalAddr)),
}
return (&net.Dialer{
Timeout: time.Duration(IntValue(runtime.ConnectTimeout)) * time.Second,
DualStack: true,
LocalAddr: netAddr,
}).DialContext(ctx, network, address)
}
return dialer.DialContext(ctx, network, address)
return (&net.Dialer{
Timeout: time.Duration(IntValue(runtime.ConnectTimeout)) * time.Second,
DualStack: true,
}).DialContext(ctx, network, address)
}
}
-215
View File
@@ -193,150 +193,6 @@ func TestConvertType(t *testing.T) {
utils.AssertEqual(t, "test", string(out.Body))
}
// TestConvertChan tests the ConvertChan function
func TestConvertChan(t *testing.T) {
// Test case 1: Successful conversion and sending to channel
t.Run("SuccessfulConversion", func(t *testing.T) {
// Create a channel to receive the converted data
ch := make(chan test, 1)
// Source data to convert
src := map[string]interface{}{
"key": 123,
"body": []byte("test"),
}
// Perform conversion
err := ConvertChan(src, ch)
// Check for errors
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
utils.AssertNil(t, err)
// Check if data was sent to channel
select {
case result := <-ch:
utils.AssertEqual(t, "123", result.Key)
utils.AssertEqual(t, "test", string(result.Body))
}
})
// Test case 2: Invalid destination channel (not a channel)
t.Run("InvalidDestChan", func(t *testing.T) {
src := map[string]interface{}{
"test": "data",
}
// Pass a non-channel type
err := ConvertChan(src, "not_a_channel")
if err == nil {
t.Error("Expected error for invalid channel, got nil")
}
expected := "destChan must be a channel"
if err.Error() != expected {
t.Errorf("Expected error message '%s', got '%s'", expected, err.Error())
}
})
// Test case 3: Send-only channel
t.Run("SendOnlyChannel", func(t *testing.T) {
// Create a send-only channel
ch := make(chan<- map[string]interface{}, 1)
src := map[string]interface{}{
"test": "data",
}
err := ConvertChan(src, ch)
if err == nil {
t.Error("Expected error for send-only channel, got nil")
}
expected := "destChan must be a receive or bidirectional channel"
if err.Error() != expected {
t.Errorf("Expected error message '%s', got '%s'", expected, err.Error())
}
})
// Test case 4: Conversion with struct
t.Run("StructConversion", func(t *testing.T) {
type TestStruct struct {
Name string `json:"name"`
Age int `json:"age"`
}
ch := make(chan TestStruct, 1)
// Source data matching struct fields
src := map[string]interface{}{
"name": "Alice",
"age": 30,
}
err := ConvertChan(src, ch)
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
select {
case result := <-ch:
if result.Name != "Alice" || result.Age != 30 {
t.Errorf("Expected {Name: Alice, Age: 30}, got %v", result)
}
default:
t.Error("Expected data in channel, but channel is empty")
}
})
// Test case 5: Nil source data
t.Run("NilSource", func(t *testing.T) {
ch := make(chan map[string]interface{}, 1)
err := ConvertChan(nil, ch)
// Depending on implementation, this might error or succeed
// Here we're testing it doesn't panic
if err != nil {
// If there's an error, that's fine, just make sure it's handled
t.Logf("Nil source resulted in error (acceptable): %v", err)
} else {
// If no error, check what was sent
select {
case result := <-ch:
if result == nil {
t.Log("Nil source correctly handled")
} else {
t.Errorf("Expected nil or error, got %v", result)
}
default:
t.Log("Channel empty after nil source, which is acceptable")
}
}
})
}
// BenchmarkConvertChan benchmarks the ConvertChan function
func BenchmarkConvertChan(b *testing.B) {
ch := make(chan map[string]interface{}, 1)
src := map[string]interface{}{
"name": "benchmark_test",
"value": 12345,
"active": true,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ConvertChan(src, ch)
<-ch // Clear the channel
}
}
func TestRuntimeObject(t *testing.T) {
runtimeobject := NewRuntimeObject(nil)
utils.AssertNil(t, runtimeobject.IgnoreSSL)
@@ -732,37 +588,12 @@ func Test_DoRequest(t *testing.T) {
return mockResponse(200, ``, nil)
}
}
// Test socks5 proxy with user:password@host format
runtimeObj["socks5Proxy"] = "socks5://someuser:somepassword@ecs.aliyun.com"
runtimeObj["localAddr"] = "127.0.0.1"
resp, err = DoRequest(request, NewRuntimeObject(runtimeObj))
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
// Test socks5 proxy with explicit port
runtimeObj["socks5Proxy"] = "socks5://someuser:somepassword@ecs.aliyun.com:1080"
resp, err = DoRequest(request, NewRuntimeObject(runtimeObj))
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
// Test socks5 proxy without authentication
runtimeObj["socks5Proxy"] = "socks5://proxy.example.com:1080"
resp, err = DoRequest(request, NewRuntimeObject(runtimeObj))
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
// Test socks5 proxy with IPv6 address
runtimeObj["socks5Proxy"] = "socks5://[::1]:1080"
resp, err = DoRequest(request, NewRuntimeObject(runtimeObj))
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
// Test socks5 proxy with IPv6 and authentication
runtimeObj["socks5Proxy"] = "socks5://user:pass@[2001:db8::1]:1080"
resp, err = DoRequest(request, NewRuntimeObject(runtimeObj))
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
runtimeObj["key"] = "private rsa key"
runtimeObj["cert"] = "private certification"
runtimeObj["ca"] = "private ca"
@@ -1531,49 +1362,3 @@ func TestForceUint64(t *testing.T) {
}
}
}
func Test_getLocalAddr(t *testing.T) {
// Test empty address
addr := getLocalAddr("")
utils.AssertNil(t, addr)
// Test valid IPv4 address
addr = getLocalAddr("127.0.0.1")
utils.AssertNotNil(t, addr)
utils.AssertEqual(t, "127.0.0.1", addr.IP.String())
// Test valid IPv6 address
addr = getLocalAddr("::1")
utils.AssertNotNil(t, addr)
utils.AssertEqual(t, "::1", addr.IP.String())
// Test invalid IP
addr = getLocalAddr("invalid")
utils.AssertNotNil(t, addr)
utils.AssertNil(t, addr.IP)
}
func Test_setDialContext(t *testing.T) {
runtime := &RuntimeObject{
ConnectTimeout: Int(1000),
LocalAddr: String("127.0.0.1"),
}
dialerFunc := setDialContext(runtime)
utils.AssertNotNil(t, dialerFunc)
}
func Test_TimeoutLogic(t *testing.T) {
runtime := &RuntimeObject{
ConnectTimeout: Int(1000),
ReadTimeout: Int(2000),
}
req := &Request{
Protocol: String("http"),
Domain: String("localhost"),
}
trans, err := getHttpTransport(req, runtime)
utils.AssertNil(t, err)
utils.AssertNotNil(t, trans)
utils.AssertEqual(t, time.Duration(2000)*time.Millisecond, trans.ResponseHeaderTimeout)
}
-308
View File
File diff suppressed because it is too large Load Diff
-485
View File
File diff suppressed because it is too large Load Diff
+16 -94
View File
@@ -3,63 +3,44 @@ package dara
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"strings"
"fmt"
)
// 定义 Event 结构体
type SSEEvent struct {
Id *string
ID *string
Event *string
Data *string
Retry *int
}
// 解析单个事件
func parseEvent(lines []string) *SSEEvent {
event := &SSEEvent{}
for _, line := range lines {
if strings.HasPrefix(line, "data:") {
var data string
if strings.HasPrefix(line, "data: ") {
data = strings.TrimPrefix(line, "data: ") + "\n"
} else {
data = strings.TrimPrefix(line, "data:") + "\n"
}
if strings.HasPrefix(line, "data: ") {
data := strings.TrimPrefix(line, "data: ") + "\n"
if event.Data == nil {
event.Data = new(string)
}
*event.Data += data
} else if strings.HasPrefix(line, "event:") {
var eventName string
if strings.HasPrefix(line, "event: ") {
eventName = strings.TrimPrefix(line, "event: ")
} else {
eventName = strings.TrimPrefix(line, "event:")
}
} else if strings.HasPrefix(line, "event: ") {
eventName := strings.TrimPrefix(line, "event: ")
event.Event = &eventName
} else if strings.HasPrefix(line, "id:") {
var id string
if strings.HasPrefix(line, "id: ") {
id = strings.TrimPrefix(line, "id: ")
} else {
id = strings.TrimPrefix(line, "id:")
}
event.Id = &id
} else if strings.HasPrefix(line, "retry:") {
var retryStr string
if strings.HasPrefix(line, "retry: ") {
retryStr = strings.TrimPrefix(line, "retry: ")
} else {
retryStr = strings.TrimPrefix(line, "retry:")
}
} else if strings.HasPrefix(line, "id: ") {
id := strings.TrimPrefix(line, "id: ")
event.ID = &id
} else if strings.HasPrefix(line, "retry: ") {
var retry int
fmt.Sscanf(retryStr, "%d", &retry)
fmt.Sscanf(strings.TrimPrefix(line, "retry: "), "%d", &retry)
event.Retry = &retry
}
}
// Remove last newline from data
if event.Data != nil {
data := strings.TrimRight(*event.Data, "\n")
event.Data = &data
@@ -151,65 +132,6 @@ func ReadAsSSE(body io.ReadCloser, eventChannel chan *SSEEvent, errorChannel cha
eventLines = append(eventLines, line)
}
}()
}
func ReadAsSSEWithContext(ctx context.Context, body io.ReadCloser, eventChannel chan *SSEEvent, errorChannel chan error) {
go func() {
defer func() {
body.Close()
close(eventChannel)
}()
reader := bufio.NewReader(body)
var eventLines []string
for {
select {
case <-ctx.Done():
errorChannel <- ctx.Err()
return
default:
}
line, err := reader.ReadString('\n')
if err != nil {
if err == io.EOF {
// Handle the end of the stream and possibly pending event
if len(eventLines) > 0 {
event := parseEvent(eventLines)
select {
case eventChannel <- event:
case <-ctx.Done():
errorChannel <- ctx.Err()
return
}
}
errorChannel <- nil
return
}
errorChannel <- err
return
}
line = strings.TrimRight(line, "\n")
if line == "" {
// End of an SSE event
if len(eventLines) > 0 {
event := parseEvent(eventLines)
select {
case eventChannel <- event:
case <-ctx.Done():
errorChannel <- ctx.Err()
return
}
eventLines = []string{} // Reset for the next event
}
continue
}
eventLines = append(eventLines, line)
}
}()
return
}
-464
View File
File diff suppressed because it is too large Load Diff
+15 -14
View File
@@ -386,7 +386,7 @@ func DoRequest(request *Request, requestRuntime map[string]interface{}) (respons
if !defaultClient.ifInit || defaultClient.httpClient.Transport == nil {
defaultClient.httpClient.Transport = trans
}
defaultClient.httpClient.Timeout = time.Duration(IntValue(runtimeObject.ConnectTimeout)+IntValue(runtimeObject.ReadTimeout)) * time.Millisecond
defaultClient.httpClient.Timeout = time.Duration(IntValue(runtimeObject.ReadTimeout)) * time.Millisecond
defaultClient.ifInit = true
defaultClient.Unlock()
}
@@ -442,7 +442,6 @@ func DoRequest(request *Request, requestRuntime map[string]interface{}) (respons
func getHttpTransport(req *Request, runtime *RuntimeObject) (*http.Transport, error) {
trans := new(http.Transport)
trans.ResponseHeaderTimeout = time.Duration(IntValue(runtime.ReadTimeout)) * time.Millisecond
httpProxy, err := getHttpProxy(StringValue(req.Protocol), StringValue(req.Domain), runtime)
if err != nil {
return nil, err
@@ -496,7 +495,7 @@ func getHttpTransport(req *Request, runtime *RuntimeObject) (*http.Transport, er
Password: password,
}
}
dialer, err := proxy.SOCKS5(strings.ToLower(StringValue(runtime.Socks5NetWork)), socks5Proxy.Host, auth,
dialer, err := proxy.SOCKS5(strings.ToLower(StringValue(runtime.Socks5NetWork)), socks5Proxy.String(), auth,
&net.Dialer{
Timeout: time.Duration(IntValue(runtime.ConnectTimeout)) * time.Millisecond,
DualStack: true,
@@ -603,7 +602,7 @@ func getSocks5Proxy(runtime *RuntimeObject) (proxy *url.URL, err error) {
func getLocalAddr(localAddr string) (addr *net.TCPAddr) {
if localAddr != "" {
addr = &net.TCPAddr{
IP: net.ParseIP(localAddr),
IP: []byte(localAddr),
}
}
return addr
@@ -611,18 +610,20 @@ func getLocalAddr(localAddr string) (addr *net.TCPAddr) {
func setDialContext(runtime *RuntimeObject) func(cxt context.Context, net, addr string) (c net.Conn, err error) {
return func(ctx context.Context, network, address string) (net.Conn, error) {
timeout := time.Duration(IntValue(runtime.ConnectTimeout)) * time.Millisecond
dialer := &net.Dialer{
Timeout: timeout,
Resolver: &net.Resolver{
PreferGo: false,
},
DualStack: true,
}
if runtime.LocalAddr != nil && StringValue(runtime.LocalAddr) != "" {
dialer.LocalAddr = getLocalAddr(StringValue(runtime.LocalAddr))
netAddr := &net.TCPAddr{
IP: []byte(StringValue(runtime.LocalAddr)),
}
return (&net.Dialer{
Timeout: time.Duration(IntValue(runtime.ConnectTimeout)) * time.Second,
DualStack: true,
LocalAddr: netAddr,
}).DialContext(ctx, network, address)
}
return dialer.DialContext(ctx, network, address)
return (&net.Dialer{
Timeout: time.Duration(IntValue(runtime.ConnectTimeout)) * time.Second,
DualStack: true,
}).DialContext(ctx, network, address)
}
}
-71
View File
@@ -560,37 +560,12 @@ func Test_DoRequest(t *testing.T) {
return mockResponse(200, ``, nil)
}
}
// Test socks5 proxy with user:password@host format
runtimeObj["socks5Proxy"] = "socks5://someuser:somepassword@ecs.aliyun.com"
runtimeObj["localAddr"] = "127.0.0.1"
resp, err = DoRequest(request, runtimeObj)
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
// Test socks5 proxy with explicit port
runtimeObj["socks5Proxy"] = "socks5://someuser:somepassword@ecs.aliyun.com:1080"
resp, err = DoRequest(request, runtimeObj)
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
// Test socks5 proxy without authentication
runtimeObj["socks5Proxy"] = "socks5://proxy.example.com:1080"
resp, err = DoRequest(request, runtimeObj)
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
// Test socks5 proxy with IPv6 address
runtimeObj["socks5Proxy"] = "socks5://[::1]:1080"
resp, err = DoRequest(request, runtimeObj)
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
// Test socks5 proxy with IPv6 and authentication
runtimeObj["socks5Proxy"] = "socks5://user:pass@[2001:db8::1]:1080"
resp, err = DoRequest(request, runtimeObj)
utils.AssertNil(t, err)
utils.AssertEqual(t, "test", StringValue(resp.Headers["tea"]))
runtimeObj["key"] = "private rsa key"
runtimeObj["cert"] = "private certification"
runtimeObj["ca"] = "private ca"
@@ -967,49 +942,3 @@ func Test_TransInt32AndInt(t *testing.T) {
b := ToInt32(a)
utils.AssertEqual(t, Int32Value(b), int32(10))
}
func Test_getLocalAddr(t *testing.T) {
// Test empty address
addr := getLocalAddr("")
utils.AssertNil(t, addr)
// Test valid IPv4 address
addr = getLocalAddr("127.0.0.1")
utils.AssertNotNil(t, addr)
utils.AssertEqual(t, "127.0.0.1", addr.IP.String())
// Test valid IPv6 address
addr = getLocalAddr("::1")
utils.AssertNotNil(t, addr)
utils.AssertEqual(t, "::1", addr.IP.String())
// Test invalid IP
addr = getLocalAddr("invalid")
utils.AssertNotNil(t, addr)
utils.AssertNil(t, addr.IP)
}
func Test_setDialContext(t *testing.T) {
runtime := &RuntimeObject{
ConnectTimeout: Int(1000),
LocalAddr: String("127.0.0.1"),
}
dialerFunc := setDialContext(runtime)
utils.AssertNotNil(t, dialerFunc)
}
func Test_TimeoutLogic(t *testing.T) {
runtime := &RuntimeObject{
ConnectTimeout: Int(1000),
ReadTimeout: Int(2000),
}
req := &Request{
Protocol: String("http"),
Domain: String("localhost"),
}
trans, err := getHttpTransport(req, runtime)
utils.AssertNil(t, err)
utils.AssertNotNil(t, trans)
utils.AssertEqual(t, time.Duration(2000)*time.Millisecond, trans.ResponseHeaderTimeout)
}