From 804c1d4d93b84dc2c727f2f6ac94c73afedac582 Mon Sep 17 00:00:00 2001 From: Austin Bischoff Date: Mon, 9 Dec 2019 14:53:58 -0600 Subject: [PATCH] Update http refresh to use url builder. Fixes #1065 (#1133) --- stored_requests/events/http/http.go | 30 ++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/stored_requests/events/http/http.go b/stored_requests/events/http/http.go index 94d8de650cd..4f141dac5cd 100644 --- a/stored_requests/events/http/http.go +++ b/stored_requests/events/http/http.go @@ -6,6 +6,7 @@ import ( "encoding/json" "io/ioutil" httpCore "net/http" + "net/url" "time" "golang.org/x/net/context/ctxhttp" @@ -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),