Skip to content

Commit aae1f75

Browse files
committed
add scheme if not present in url
1 parent 4cef759 commit aae1f75

File tree

1 file changed

+11
-3
lines changed
  • code/go/0chain.net/core/util

1 file changed

+11
-3
lines changed

code/go/0chain.net/core/util/http.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"io"
77
"net/http"
8+
"net/url"
89
"sync"
910
"time"
1011

@@ -41,19 +42,26 @@ func SendMultiPostRequest(urls []string, data []byte) {
4142
wg.Wait()
4243
}
4344

44-
func SendPostRequest(url string, data []byte, wg *sync.WaitGroup) (body []byte, err error) {
45+
func SendPostRequest(postURL string, data []byte, wg *sync.WaitGroup) (body []byte, err error) {
4546
if wg != nil {
4647
defer wg.Done()
4748
}
4849
var resp *http.Response
50+
u, err := url.Parse(postURL)
51+
if err != nil {
52+
return nil, err
53+
}
54+
if u.Scheme == "" {
55+
u.Scheme = "https"
56+
}
4957
for i := 0; i < MAX_RETRIES; i++ {
5058
var (
5159
req *http.Request
5260
ctx context.Context
5361
cncl context.CancelFunc
5462
)
5563

56-
req, ctx, cncl, err = NewHTTPRequest(http.MethodPost, url, data)
64+
req, ctx, cncl, err = NewHTTPRequest(http.MethodPost, u.String(), data)
5765
defer cncl()
5866

5967
resp, err = http.DefaultClient.Do(req.WithContext(ctx))
@@ -71,7 +79,7 @@ func SendPostRequest(url string, data []byte, wg *sync.WaitGroup) (body []byte,
7179
time.Sleep(SLEEP_BETWEEN_RETRIES * time.Second)
7280
}
7381
if resp == nil || err != nil {
74-
Logger.Error("Failed after multiple retries", zap.Any("url", url), zap.Int("retried", MAX_RETRIES), zap.Error(err))
82+
Logger.Error("Failed after multiple retries", zap.Any("url", u.String()), zap.Int("retried", MAX_RETRIES), zap.Error(err))
7583
return nil, err
7684
}
7785
if resp.Body == nil {

0 commit comments

Comments
 (0)