Browse Source

request content type

ls 5 years ago
parent
commit
a08c1984b8
1 changed files with 15 additions and 2 deletions
  1. 15 2
      request.go

+ 15 - 2
request.go

@@ -12,10 +12,23 @@ import (
 )
 
 const (
+	// ReqContentTypeURL application/x-www-form-urlencoded
+	ReqContentTypeURL = `application/x-www-form-urlencoded; charset=utf-8`
+	// ReqContentTypeJSON application/json
+	ReqContentTypeJSON = `application/json; charset=utf-8`
+	// ReqContentTypeXML application/xml
+	ReqContentTypeXML = `application/xml; charset=utf-8`
+	// ReqContentTypeMultipart multipart/form-data
+	ReqContentTypeMultipart = `multipart/form-data`
+
 	// RequestTimeOut http request timeout (second)
 	RequestTimeOut = 30
 )
 
+var (
+	reqTimeOut = time.Duration(RequestTimeOut)
+)
+
 // GetRealIP get real IP from Request
 func GetRealIP(req *http.Request) (ip string) {
 	if ips := req.Header["X-Real-Ip"]; ips != nil {
@@ -38,10 +51,10 @@ func newRequest(method, uri, certPath, keyPath string, header map[string]string,
 			if err != nil {
 				return nil, err
 			}
-			conn.SetDeadline(time.Now().Add(time.Second * RequestTimeOut))
+			conn.SetDeadline(time.Now().Add(time.Second * reqTimeOut))
 			return conn, nil
 		},
-		ResponseHeaderTimeout: time.Second * RequestTimeOut,
+		ResponseHeaderTimeout: time.Second * reqTimeOut,
 	}
 
 	if certPath != "" {