@@ -2,6 +2,7 @@ package http
22
33import (
44 "encoding/json"
5+ "fmt"
56 commonCliConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
67 "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
78 "github.com/jfrog/jfrog-client-go/auth"
@@ -13,6 +14,8 @@ import (
1314 "net/http"
1415)
1516
17+ const applicationApiPath = "application/api"
18+
1619type AppHttpClient interface {
1720 GetHttpClient () * jfroghttpclient.JfrogHttpClient
1821 Post (path string , requestBody interface {}) (resp * http.Response , body []byte , err error )
@@ -76,21 +79,35 @@ func (c *appHttpClient) GetHttpClient() *jfroghttpclient.JfrogHttpClient {
7679}
7780
7881func (c * appHttpClient ) Post (path string , requestBody interface {}) (resp * http.Response , body []byte , err error ) {
79- url , err := utils .BuildUrl (c .serverDetails .Url , path , nil )
82+ url , err := utils .BuildUrl (c .serverDetails .Url , applicationApiPath + path , nil )
8083 if err != nil {
8184 return nil , nil , err
8285 }
8386
84- var requestContent []byte
85- if requestBody != nil {
86- requestContent , err = json .Marshal (requestBody )
87- if err != nil {
88- return nil , nil , errorutils .CheckError (err )
89- }
87+ requestContent , err := c .toJsonBytes (requestBody )
88+ if err != nil {
89+ return nil , nil , err
9090 }
9191
92+ println ("url: " , url )
93+ return c .client .SendPost (url , requestContent , c .getJsonHttpClientDetails ())
94+ }
95+
96+ func (c * appHttpClient ) toJsonBytes (payload interface {}) ([]byte , error ) {
97+ if payload == nil {
98+ return nil , fmt .Errorf ("request payload is required" )
99+ }
100+
101+ jsonBytes , err := json .Marshal (payload )
102+ if err != nil {
103+ return nil , errorutils .CheckError (err )
104+ }
105+ return jsonBytes , nil
106+ }
107+
108+ func (c * appHttpClient ) getJsonHttpClientDetails () * httputils.HttpClientDetails {
92109 var httpClientDetails httputils.HttpClientDetails
93110 httpClientDetails = c .authDetails .CreateHttpClientDetails ()
94111 httpClientDetails .SetContentTypeApplicationJson ()
95- return c . client . SendPost ( url , requestContent , & httpClientDetails )
112+ return & httpClientDetails
96113}
0 commit comments