From 04cc91bb5fd27d0815c24cf813254c4d5e307672 Mon Sep 17 00:00:00 2001 From: Sinh Date: Tue, 4 Oct 2022 16:29:34 +0700 Subject: [PATCH] add header content type for OP --- partnerapi/globalcare/globale_care.go | 3 ++- partnerapi/onpoint/onpoint.go | 8 +++++--- partnerapi/tnc/tnc.go | 5 +++-- util/httputil/const.go | 8 ++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 util/httputil/const.go diff --git a/partnerapi/globalcare/globale_care.go b/partnerapi/globalcare/globale_care.go index 3a2ab0c..a8cb0c6 100644 --- a/partnerapi/globalcare/globale_care.go +++ b/partnerapi/globalcare/globale_care.go @@ -18,6 +18,7 @@ import ( "github.com/thoas/go-funk" "github.com/Selly-Modules/3pl/util/base64" + "github.com/Selly-Modules/3pl/util/httputil" "github.com/Selly-Modules/3pl/util/pjson" ) @@ -72,7 +73,7 @@ func (c *Client) CreateOrder(data CreateOrderPayload) (*CreateOrderResponseDecod Method: http.MethodPost, Data: pjson.ToJSONString(body), Header: map[string]string{ - "Content-Type": "application/json", + httputil.HeaderKeyContentType: httputil.HeaderValueApplicationJSON, }, }, } diff --git a/partnerapi/onpoint/onpoint.go b/partnerapi/onpoint/onpoint.go index 1d73753..000f57f 100644 --- a/partnerapi/onpoint/onpoint.go +++ b/partnerapi/onpoint/onpoint.go @@ -12,6 +12,7 @@ import ( "github.com/Selly-Modules/natsio/model" "github.com/Selly-Modules/natsio/subject" + "github.com/Selly-Modules/3pl/util/httputil" "github.com/Selly-Modules/3pl/util/pjson" ) @@ -171,9 +172,10 @@ func (c *Client) requestHttpViaNats(data model.CommunicationRequestHttp, res int // sign data sign := hashSHA256AndUppercase(s, c.secretKey) data.Payload.Header = map[string]string{ - headerXAPIKey: c.apiKey, - headerXSignature: sign, - headerXTimestamp: ts, + headerXAPIKey: c.apiKey, + headerXSignature: sign, + headerXTimestamp: ts, + httputil.HeaderKeyContentType: httputil.HeaderValueApplicationJSON, } return ec.Request(subject.Communication.RequestHTTP, data, res) diff --git a/partnerapi/tnc/tnc.go b/partnerapi/tnc/tnc.go index de2c7e0..be3a583 100644 --- a/partnerapi/tnc/tnc.go +++ b/partnerapi/tnc/tnc.go @@ -12,6 +12,7 @@ import ( "github.com/Selly-Modules/natsio/subject" "github.com/nats-io/nats.go" + "github.com/Selly-Modules/3pl/util/httputil" "github.com/Selly-Modules/3pl/util/pjson" ) @@ -230,7 +231,7 @@ func (c *Client) auth() (*authRes, error) { body := v.Encode() header := map[string]string{ - "Content-Type": "application/x-www-form-urlencoded", + httputil.HeaderKeyContentType: httputil.HeaderValueApplicationURLEncoded, } apiURL := baseURLAuthENVMapping[c.env] + fmt.Sprintf(apiPathAuth, c.realm) natsPayload := model.CommunicationRequestHttp{ @@ -276,7 +277,7 @@ func (c *Client) auth() (*authRes, error) { func (c *Client) getRequestHeader() map[string]string { m := map[string]string{ - "Content-Type": "application/json", + httputil.HeaderKeyContentType: httputil.HeaderValueApplicationJSON, } token, err := c.getToken() if err != nil { diff --git a/util/httputil/const.go b/util/httputil/const.go new file mode 100644 index 0000000..c708838 --- /dev/null +++ b/util/httputil/const.go @@ -0,0 +1,8 @@ +package httputil + +const ( + HeaderKeyContentType = "Content-Type" + + HeaderValueApplicationJSON = "application/json" + HeaderValueApplicationURLEncoded = "application/x-www-form-urlencoded" +)