mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Removed error from HTTPPoster constructor
This commit is contained in:
committed by
Dan Christian Bogos
parent
33e863e413
commit
789953e5a0
@@ -52,11 +52,8 @@ func (aL *actHTTPPost) execute(_ context.Context, data utils.MapStorage, _ strin
|
||||
}
|
||||
var partExec bool
|
||||
for _, actD := range aL.cfg().Diktats {
|
||||
var pstr *engine.HTTPPoster
|
||||
if pstr, err = engine.NewHTTPPoster(config.CgrConfig().GeneralCfg().ReplyTimeout, actD.Path,
|
||||
utils.ContentJSON, aL.config.GeneralCfg().PosterAttempts); err != nil {
|
||||
return
|
||||
}
|
||||
pstr := engine.NewHTTPPoster(config.CgrConfig().GeneralCfg().ReplyTimeout, actD.Path,
|
||||
utils.ContentJSON, aL.config.GeneralCfg().PosterAttempts)
|
||||
if async, has := aL.cfg().Opts[utils.MetaAsync]; has && utils.IfaceAsString(async) == utils.TrueStr {
|
||||
go aL.post(pstr, body, actD.Path)
|
||||
} else if err = aL.post(pstr, body, actD.Path); err != nil {
|
||||
|
||||
@@ -39,7 +39,7 @@ func NewHTTPjsonMapEE(cgrCfg *config.CGRConfig, cfgIdx int, filterS *engine.Filt
|
||||
dc: dc,
|
||||
}
|
||||
|
||||
pstrJSON.pstr, err = engine.NewHTTPPoster(cgrCfg.GeneralCfg().ReplyTimeout,
|
||||
pstrJSON.pstr = engine.NewHTTPPoster(cgrCfg.GeneralCfg().ReplyTimeout,
|
||||
cgrCfg.EEsCfg().Exporters[cfgIdx].ExportPath,
|
||||
utils.PosterTransportContentTypes[cgrCfg.EEsCfg().Exporters[cfgIdx].Type],
|
||||
cgrCfg.EEsCfg().Exporters[cfgIdx].Attempts)
|
||||
|
||||
@@ -33,7 +33,7 @@ func NewHTTPPostEe(cgrCfg *config.CGRConfig, cfgIdx int, filterS *engine.FilterS
|
||||
dc utils.MapStorage) (httpPost *HTTPPost, err error) {
|
||||
httpPost = &HTTPPost{id: cgrCfg.EEsCfg().Exporters[cfgIdx].ID,
|
||||
cgrCfg: cgrCfg, cfgIdx: cfgIdx, filterS: filterS, dc: dc}
|
||||
httpPost.httpPoster, err = engine.NewHTTPPoster(cgrCfg.GeneralCfg().ReplyTimeout,
|
||||
httpPost.httpPoster = engine.NewHTTPPoster(cgrCfg.GeneralCfg().ReplyTimeout,
|
||||
cgrCfg.EEsCfg().Exporters[cfgIdx].ExportPath,
|
||||
utils.PosterTransportContentTypes[cgrCfg.EEsCfg().Exporters[cfgIdx].Type],
|
||||
cgrCfg.EEsCfg().Exporters[cfgIdx].Attempts)
|
||||
|
||||
@@ -154,13 +154,10 @@ func (expEv *ExportEvents) ReplayFailedPosts(attempts int) (failedEvents *Export
|
||||
keyFunc := func() string { return utils.EmptyString }
|
||||
switch expEv.Format {
|
||||
case utils.MetaHTTPjsonCDR, utils.MetaHTTPjsonMap, utils.MetaHTTPjson, utils.MetaHTTPPost:
|
||||
var pstr *HTTPPoster
|
||||
pstr, err = NewHTTPPoster(config.CgrConfig().GeneralCfg().ReplyTimeout, expEv.Path,
|
||||
pstr := NewHTTPPoster(config.CgrConfig().GeneralCfg().ReplyTimeout, expEv.Path,
|
||||
utils.PosterTransportContentTypes[expEv.Format],
|
||||
config.CgrConfig().GeneralCfg().PosterAttempts)
|
||||
if err != nil {
|
||||
return expEv, err
|
||||
}
|
||||
|
||||
for _, ev := range expEv.Events {
|
||||
req := ev.(*HTTPPosterRequest)
|
||||
err = pstr.PostValues(req.Body, req.Header)
|
||||
|
||||
@@ -55,16 +55,13 @@ func HTTPPostJSON(url string, content []byte) (respBody []byte, err error) {
|
||||
|
||||
// NewHTTPPoster return a new HTTP poster
|
||||
func NewHTTPPoster(replyTimeout time.Duration, addr, contentType string,
|
||||
attempts int) (httposter *HTTPPoster, err error) {
|
||||
if !utils.SliceHasMember([]string{utils.ContentForm, utils.ContentJSON, utils.ContentText}, contentType) {
|
||||
return nil, fmt.Errorf("unsupported ContentType: %s", contentType)
|
||||
}
|
||||
attempts int) (httposter *HTTPPoster) {
|
||||
return &HTTPPoster{
|
||||
httpClient: &http.Client{Transport: httpPstrTransport, Timeout: replyTimeout},
|
||||
addr: addr,
|
||||
contentType: contentType,
|
||||
attempts: attempts,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// HTTPPoster used to post cdrs
|
||||
|
||||
@@ -68,10 +68,8 @@ func TestHttpJsonPoster(t *testing.T) {
|
||||
config.CgrConfig().GeneralCfg().FailedPostsDir = "/tmp"
|
||||
content := &TestContent{Var1: "Val1", Var2: "Val2"}
|
||||
jsn, _ := json.Marshal(content)
|
||||
pstr, err := NewHTTPPoster(2*time.Second, "http://localhost:8080/invalid", utils.ContentJSON, 3)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
pstr := NewHTTPPoster(2*time.Second, "http://localhost:8080/invalid", utils.ContentJSON, 3)
|
||||
|
||||
if err = pstr.PostValues(jsn, make(http.Header)); err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
@@ -101,10 +99,7 @@ func TestHttpBytesPoster(t *testing.T) {
|
||||
content := []byte(`Test
|
||||
Test2
|
||||
`)
|
||||
pstr, err := NewHTTPPoster(2*time.Second, "http://localhost:8080/invalid", utils.ContentText, 3)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
pstr := NewHTTPPoster(2*time.Second, "http://localhost:8080/invalid", utils.ContentText, 3)
|
||||
if err = pstr.PostValues(content, make(http.Header)); err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user