|
@@ -138,7 +138,8 @@ func HTTPListenAndServe(addr string, router http.Handler) {
|
|
log.Println("Exit", <-errc)
|
|
log.Println("Exit", <-errc)
|
|
}
|
|
}
|
|
|
|
|
|
-func newRequest(method, uri, certPath, keyPath string, header map[string]string, body io.Reader) (res *http.Response, err error) {
|
|
|
|
|
|
+// newHTTPRequest http request
|
|
|
|
+func newHTTPRequest(method, uri, certPath, keyPath string, header map[string]string, cookies []*http.Cookie, body io.Reader) (res *http.Response, err error) {
|
|
t := &http.Transport{
|
|
t := &http.Transport{
|
|
Dial: func(netw, addr string) (net.Conn, error) {
|
|
Dial: func(netw, addr string) (net.Conn, error) {
|
|
conn, err := net.DialTimeout(netw, addr, time.Second*RequestTimeOut)
|
|
conn, err := net.DialTimeout(netw, addr, time.Second*RequestTimeOut)
|
|
@@ -165,6 +166,10 @@ func newRequest(method, uri, certPath, keyPath string, header map[string]string,
|
|
req *http.Request
|
|
req *http.Request
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ if cookies != nil {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
if body != nil {
|
|
if body != nil {
|
|
req, err = http.NewRequest(method, uri, body)
|
|
req, err = http.NewRequest(method, uri, body)
|
|
} else {
|
|
} else {
|
|
@@ -211,7 +216,7 @@ func readBody(res *http.Response) (msg Message, err error) {
|
|
// Post HTTP request POST
|
|
// Post HTTP request POST
|
|
func Post(uri, certPath, keyPath string, header map[string]string, data io.Reader) (msg Message, err error) {
|
|
func Post(uri, certPath, keyPath string, header map[string]string, data io.Reader) (msg Message, err error) {
|
|
var res *http.Response
|
|
var res *http.Response
|
|
- if res, err = newRequest("POST", uri, certPath, keyPath, header, data); err != nil {
|
|
|
|
|
|
+ if res, err = newHTTPRequest("POST", uri, certPath, keyPath, header, nil, data); err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
@@ -223,7 +228,7 @@ func Post(uri, certPath, keyPath string, header map[string]string, data io.Reade
|
|
// Get HTTP request GET
|
|
// Get HTTP request GET
|
|
func Get(uri, certPath, keyPath string, header map[string]string) (msg Message, err error) {
|
|
func Get(uri, certPath, keyPath string, header map[string]string) (msg Message, err error) {
|
|
var res *http.Response
|
|
var res *http.Response
|
|
- if res, err = newRequest("GET", uri, certPath, keyPath, header, nil); err != nil {
|
|
|
|
|
|
+ if res, err = newHTTPRequest("GET", uri, certPath, keyPath, header, nil, nil); err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|