Compare commits
No commits in common. "b897a4dfda5481f04e716f503d7b634bd399bd70" and "e72fa38b968cf71c13cd5260253026a4e108e6bf" have entirely different histories.
b897a4dfda
...
e72fa38b96
8
go.mod
8
go.mod
@ -1,3 +1,11 @@
|
|||||||
module git.3crabs.ru/VLADIMIR/net
|
module git.3crabs.ru/VLADIMIR/net
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
|
require github.com/stretchr/testify v1.8.4
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
9
go.sum
9
go.sum
@ -0,0 +1,9 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
@ -1,10 +1,9 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type client struct{}
|
type client struct{}
|
||||||
@ -20,22 +19,21 @@ func (c *client) getIP(domain string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Do(method string, rawURl string, headers []Header) (*Response, error) {
|
func (c *client) Do(method string, url string, headers []Header) (*Response, error) {
|
||||||
u, err := url.Parse(rawURl)
|
url = strings.TrimPrefix(url, "http://")
|
||||||
if err != nil {
|
url = strings.TrimPrefix(url, "https://")
|
||||||
return nil, err
|
path := "/"
|
||||||
|
arr := strings.Split(url, "/")
|
||||||
|
if len(arr) == 2 {
|
||||||
|
path = arr[1]
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(path, "/") {
|
||||||
|
path = "/" + path
|
||||||
}
|
}
|
||||||
|
|
||||||
connectPath := c.getIP(u.Host)
|
connectPath := c.getIP(arr[0])
|
||||||
var conn net.Conn
|
conn, err := net.Dial("tcp", connectPath)
|
||||||
switch u.Scheme {
|
// conn, err := tls.Dial("tcp", connectPath, nil)
|
||||||
case "http":
|
|
||||||
conn, err = net.Dial("tcp", connectPath)
|
|
||||||
case "https":
|
|
||||||
conn, err = tls.Dial("tcp", connectPath, nil)
|
|
||||||
default:
|
|
||||||
panic("scheme not support")
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("connect " + connectPath)
|
return nil, errors.New("connect " + connectPath)
|
||||||
}
|
}
|
||||||
@ -45,7 +43,7 @@ func (c *client) Do(method string, rawURl string, headers []Header) (*Response,
|
|||||||
conn,
|
conn,
|
||||||
&Request{
|
&Request{
|
||||||
Method: method,
|
Method: method,
|
||||||
Path: u.Path,
|
Path: path,
|
||||||
Protocol: "HTTP/1.0",
|
Protocol: "HTTP/1.0",
|
||||||
Headers: headers,
|
Headers: headers,
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,7 @@ func main() {
|
|||||||
client := http.NewClient()
|
client := http.NewClient()
|
||||||
_, err := client.Do(
|
_, err := client.Do(
|
||||||
"GET",
|
"GET",
|
||||||
"http://test.ru/",
|
"http://test.ru",
|
||||||
[]http.Header{
|
[]http.Header{
|
||||||
{Name: "Host", Value: "3crabs.ru"},
|
{Name: "Host", Value: "3crabs.ru"},
|
||||||
{Name: "User-Agent", Value: "3crabs/0.0.1"},
|
{Name: "User-Agent", Value: "3crabs/0.0.1"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user