update read response
This commit is contained in:
+13
-9
@@ -6,19 +6,20 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
CRLF = []byte("\r\n")
|
||||
SP = []byte(" ")
|
||||
)
|
||||
type client struct{}
|
||||
|
||||
func getIP(domain string) string {
|
||||
func NewClient() *client {
|
||||
return &client{}
|
||||
}
|
||||
|
||||
func (c *client) getIP(domain string) string {
|
||||
if domain == "test.ru" {
|
||||
return "127.0.0.1:8081"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func Do(method string, url string, headers []Header) (*Response, error) {
|
||||
func (c *client) Do(method string, url string, headers []Header) (*Response, error) {
|
||||
url = strings.TrimPrefix(url, "http://")
|
||||
url = strings.TrimPrefix(url, "https://")
|
||||
path := "/"
|
||||
@@ -30,7 +31,7 @@ func Do(method string, url string, headers []Header) (*Response, error) {
|
||||
path = "/" + path
|
||||
}
|
||||
|
||||
connectPath := getIP(arr[0])
|
||||
connectPath := c.getIP(arr[0])
|
||||
conn, err := net.Dial("tcp", connectPath)
|
||||
// conn, err := tls.Dial("tcp", connectPath, nil)
|
||||
if err != nil {
|
||||
@@ -38,7 +39,7 @@ func Do(method string, url string, headers []Header) (*Response, error) {
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
DebugWrap(
|
||||
WriteRequestDebugWrap(
|
||||
conn,
|
||||
&Request{
|
||||
Method: method,
|
||||
@@ -48,5 +49,8 @@ func Do(method string, url string, headers []Header) (*Response, error) {
|
||||
},
|
||||
WriteRequest,
|
||||
)
|
||||
return ReadResponse(conn)
|
||||
return ReadResponseDebugWrap(
|
||||
conn,
|
||||
ReadResponse,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user