Skip to content

Commit

Permalink
Fixed typo and set application/json as default content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyaw Myint Thein committed Oct 12, 2021
1 parent cbecc45 commit 38cd38d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 9 additions & 8 deletions header2body.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rzluramartian
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"

Expand Down Expand Up @@ -43,9 +42,10 @@ func (m *Header2BodyModifier) ModifyRequest(req *http.Request) error {
if err != nil {
return err
}

switch m.ContentType {
case _contentType_applicationJSON:
default:

// default is application/json
data := make(map[string]interface{})
json.Unmarshal(body, &data) // Skip error even if it is failed

Expand All @@ -58,13 +58,14 @@ func (m *Header2BodyModifier) ModifyRequest(req *http.Request) error {
if err != nil {
return err
}
default:
return fmt.Errorf("unsupport content-type")
req.Header.Del(_contentTypeHeader)
req.Header.Set(_contentTypeHeader, _contentType_applicationJSON)
}

} else {
switch m.ContentType {
case _contentType_applicationJSON:
default:
// default is application/json
data := make(map[string]interface{})

for _, k := range m.keysToExtract {
Expand All @@ -77,8 +78,8 @@ func (m *Header2BodyModifier) ModifyRequest(req *http.Request) error {
if err != nil {
return err
}
default:
return fmt.Errorf("unsupport content-type")
req.Header.Del(_contentTypeHeader)
req.Header.Set(_contentTypeHeader, _contentType_applicationJSON)
}
}
req.ContentLength = int64(len(buf))
Expand Down
3 changes: 2 additions & 1 deletion querystring2body.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
)

const (
_contentType_applicationJSON = "appliction/json"
_contentType_applicationJSON = "application/json"
_contentType_applicationXML = "application/xml"
_contentTypeHeader = "Content-Type"
)

Expand Down

0 comments on commit 38cd38d

Please sign in to comment.