Skip to content

Commit 09a363e

Browse files
AustinbSyntaxNode
authored andcommitted
Update http refresh to use url builder. Fixes prebid#1065 (prebid#1133)
1 parent 777dd75 commit 09a363e

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

stored_requests/events/http/http.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"io/ioutil"
88
httpCore "net/http"
9+
"net/url"
910
"time"
1011

1112
"golang.org/x/net/context/ctxhttp"
@@ -94,10 +95,33 @@ func (e *HTTPEvents) refresh(ticker <-chan time.Time) {
9495
select {
9596
case thisTime := <-ticker:
9697
thisTimeInUTC := thisTime.UTC()
97-
thisEndpoint := e.Endpoint + "?last-modified=" + e.lastUpdate.Format(time.RFC3339)
98+
99+
// Parse the endpoint url defined
100+
endpointUrl, urlErr := url.Parse(e.Endpoint)
101+
102+
// Error with url parsing
103+
if urlErr != nil {
104+
glog.Errorf("Disabling refresh HTTP cache from GET '%s': %v", e.Endpoint, urlErr)
105+
return
106+
}
107+
108+
// Parse the url query string
109+
urlQuery := endpointUrl.Query()
110+
111+
// See the last-modified query param
112+
urlQuery.Set("last-modified", e.lastUpdate.Format(time.RFC3339))
113+
114+
// Rebuild
115+
endpointUrl.RawQuery = urlQuery.Encode()
116+
117+
// Convert to string
118+
endpoint := endpointUrl.String()
119+
120+
glog.Infof("Refreshing HTTP cache from GET '%s'", endpoint)
121+
98122
ctx, cancel := e.ctxProducer()
99-
resp, err := ctxhttp.Get(ctx, e.client, thisEndpoint)
100-
if respObj, ok := e.parse(thisEndpoint, resp, err); ok {
123+
resp, err := ctxhttp.Get(ctx, e.client, endpoint)
124+
if respObj, ok := e.parse(endpoint, resp, err); ok {
101125
invalidations := events.Invalidation{
102126
Requests: extractInvalidations(respObj.StoredRequests),
103127
Imps: extractInvalidations(respObj.StoredImps),

0 commit comments

Comments
 (0)