X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=dmaap-mediator-producer%2Finternal%2Frestclient%2FHTTPClient.go;fp=dmaap-mediator-producer%2Finternal%2Frestclient%2FHTTPClient.go;h=a7582c2ba71150e5a9608792a2ef88892c1f480d;hb=db7b5c801bdc96889aea18ab190f2b72fa8d8e06;hp=9a827e7ae69d02a38f5539be5e3c034e8e478b7b;hpb=9a4dbeb7183f2f5e81c40bb329e9319bb2bd560c;p=nonrtric.git diff --git a/dmaap-mediator-producer/internal/restclient/HTTPClient.go b/dmaap-mediator-producer/internal/restclient/HTTPClient.go index 9a827e7a..a7582c2b 100644 --- a/dmaap-mediator-producer/internal/restclient/HTTPClient.go +++ b/dmaap-mediator-producer/internal/restclient/HTTPClient.go @@ -34,6 +34,9 @@ import ( log "github.com/sirupsen/logrus" ) +const ContentTypeJSON = "application/json" +const ContentTypePlain = "text/plain" + // HTTPClient interface type HTTPClient interface { Get(url string) (*http.Response, error) @@ -68,16 +71,16 @@ func Get(url string, client HTTPClient) ([]byte, error) { } func Put(url string, body []byte, client HTTPClient) error { - return do(http.MethodPut, url, body, client) + return do(http.MethodPut, url, body, ContentTypeJSON, client) } -func Post(url string, body []byte, client HTTPClient) error { - return do(http.MethodPost, url, body, client) +func Post(url string, body []byte, contentType string, client HTTPClient) error { + return do(http.MethodPost, url, body, contentType, client) } -func do(method string, url string, body []byte, client HTTPClient) error { +func do(method string, url string, body []byte, contentType string, client HTTPClient) error { if req, reqErr := http.NewRequest(method, url, bytes.NewBuffer(body)); reqErr == nil { - req.Header.Set("Content-Type", "application/json") + req.Header.Set("Content-Type", contentType) if response, respErr := client.Do(req); respErr == nil { if isResponseSuccess(response.StatusCode) { return nil