Browse Source

http req with cookie

ls 5 years ago
parent
commit
5f2ccc9c64
1 changed files with 8 additions and 3 deletions
  1. 8 3
      http.go

+ 8 - 3
http.go

@@ -138,7 +138,8 @@ func HTTPListenAndServe(addr string, router http.Handler) {
 	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{
 		Dial: func(netw, addr string) (net.Conn, error) {
 			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
 	)
 
+	if cookies != nil {
+
+	}
+
 	if body != nil {
 		req, err = http.NewRequest(method, uri, body)
 	} else {
@@ -211,7 +216,7 @@ func readBody(res *http.Response) (msg Message, err error) {
 // Post HTTP request POST
 func Post(uri, certPath, keyPath string, header map[string]string, data io.Reader) (msg Message, err error) {
 	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
 	}
 	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
 func Get(uri, certPath, keyPath string, header map[string]string) (msg Message, err error) {
 	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
 	}