Allow implementation code to specify headers.
diff --git a/pagination/http.go b/pagination/http.go
index 31cde49..dd2c2d7 100644
--- a/pagination/http.go
+++ b/pagination/http.go
@@ -5,12 +5,14 @@
"io/ioutil"
"net/http"
"net/url"
+ "strings"
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
)
// LastHTTPResponse stores generic information derived from an HTTP response.
+// This exists primarily because the body of an http.Response can only be used once.
type LastHTTPResponse struct {
url.URL
http.Header
@@ -29,7 +31,7 @@
return LastHTTPResponse{}, err
}
- if resp.Header.Get("Content-Type") == "application/json" {
+ if strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
err = json.Unmarshal(rawBody, &parsedBody)
if err != nil {
return LastHTTPResponse{}, err
@@ -46,9 +48,14 @@
}
// Request performs a Perigee request and extracts the http.Response from the result.
-func Request(client *gophercloud.ServiceClient, url string) (http.Response, error) {
+func Request(client *gophercloud.ServiceClient, headers map[string]string, url string) (http.Response, error) {
+ h := client.Provider.AuthenticatedHeaders()
+ for key, value := range headers {
+ h[key] = value
+ }
+
resp, err := perigee.Request("GET", url, perigee.Options{
- MoreHeaders: client.Provider.AuthenticatedHeaders(),
+ MoreHeaders: h,
OkCodes: []int{200, 204},
})
if err != nil {
diff --git a/pagination/pager.go b/pagination/pager.go
index 52ebb96..806d98a 100644
--- a/pagination/pager.go
+++ b/pagination/pager.go
@@ -34,6 +34,9 @@
client *gophercloud.ServiceClient
createPage func(r LastHTTPResponse) Page
+
+ // Headers supplies additional HTTP headers to populate on each paged request.
+ Headers map[string]string
}
// NewPager constructs a manually-configured pager.
@@ -47,7 +50,7 @@
}
func (p Pager) fetchNextPage(url string) (Page, error) {
- resp, err := Request(p.client, url)
+ resp, err := Request(p.client, p.Headers, url)
if err != nil {
return nil, err
}