|
6 | 6 | "encoding/json"
|
7 | 7 | "io/ioutil"
|
8 | 8 | httpCore "net/http"
|
| 9 | + "net/url" |
9 | 10 | "time"
|
10 | 11 |
|
11 | 12 | "golang.org/x/net/context/ctxhttp"
|
@@ -94,10 +95,33 @@ func (e *HTTPEvents) refresh(ticker <-chan time.Time) {
|
94 | 95 | select {
|
95 | 96 | case thisTime := <-ticker:
|
96 | 97 | 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 | + |
98 | 122 | 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 { |
101 | 125 | invalidations := events.Invalidation{
|
102 | 126 | Requests: extractInvalidations(respObj.StoredRequests),
|
103 | 127 | Imps: extractInvalidations(respObj.StoredImps),
|
|
0 commit comments