Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Update http refresh to use url builder. Fixes prebid#1065 (prebid#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Austinb authored and SyntaxNode committed Dec 9, 2019
1 parent 8747dd9 commit 804c1d4
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions stored_requests/events/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"io/ioutil"
httpCore "net/http"
"net/url"
"time"

"golang.org/x/net/context/ctxhttp"
Expand Down Expand Up @@ -94,10 +95,33 @@ func (e *HTTPEvents) refresh(ticker <-chan time.Time) {
select {
case thisTime := <-ticker:
thisTimeInUTC := thisTime.UTC()
thisEndpoint := e.Endpoint + "?last-modified=" + e.lastUpdate.Format(time.RFC3339)

// Parse the endpoint url defined
endpointUrl, urlErr := url.Parse(e.Endpoint)

// Error with url parsing
if urlErr != nil {
glog.Errorf("Disabling refresh HTTP cache from GET '%s': %v", e.Endpoint, urlErr)
return
}

// Parse the url query string
urlQuery := endpointUrl.Query()

// See the last-modified query param
urlQuery.Set("last-modified", e.lastUpdate.Format(time.RFC3339))

// Rebuild
endpointUrl.RawQuery = urlQuery.Encode()

// Convert to string
endpoint := endpointUrl.String()

glog.Infof("Refreshing HTTP cache from GET '%s'", endpoint)

ctx, cancel := e.ctxProducer()
resp, err := ctxhttp.Get(ctx, e.client, thisEndpoint)
if respObj, ok := e.parse(thisEndpoint, resp, err); ok {
resp, err := ctxhttp.Get(ctx, e.client, endpoint)
if respObj, ok := e.parse(endpoint, resp, err); ok {
invalidations := events.Invalidation{
Requests: extractInvalidations(respObj.StoredRequests),
Imps: extractInvalidations(respObj.StoredImps),
Expand Down

0 comments on commit 804c1d4

Please sign in to comment.