aboutsummaryrefslogtreecommitdiff
path: root/request.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2018-02-05 21:30:33 +0100
committerStefan Majewsky <majewsky@gmx.net>2018-02-05 21:44:35 +0100
commit3a24741929cd12ffee5e54d0e9a9afb83c5069b3 (patch)
tree6a91b159d25814e873fcfae08cd40cba9b1dcc14 /request.go
parent7de32502590995ee8d7cc8b681b0f723ca35ccb0 (diff)
downloadgo-schwift-3a24741929cd12ffee5e54d0e9a9afb83c5069b3.tar.gz
redesign the header API
I'm quite satisfied with this right now (though this doesn't say anything about how I feel about it tomorrow), but it's ugly that some guts (headers.Base) are exposed in the public API.
Diffstat (limited to 'request.go')
-rw-r--r--request.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/request.go b/request.go
index 79a0296..0106d38 100644
--- a/request.go
+++ b/request.go
@@ -47,7 +47,8 @@ type Request struct {
Method string //"GET", "HEAD", "PUT", "POST" or "DELETE"
ContainerName string //empty for requests on accounts
ObjectName string //empty for requests on accounts/containers
- Options RequestOptions
+ Headers http.Header
+ Options *RequestOptions
Body io.Reader
//ExpectStatusCodes can be left empty to disable this check, otherwise
//schwift.UnexpectedStatusCodeError may be returned.
@@ -56,8 +57,7 @@ type Request struct {
//RequestOptions contains additional headers and values for request.
type RequestOptions struct {
- Headers http.Header
- Values url.Values
+ Values url.Values
}
//URL returns the full URL for this request.
@@ -94,7 +94,11 @@ func (r Request) do(client *gophercloud.ServiceClient, afterReauth bool) (*http.
provider := client.ProviderClient
//build URL
- uri, err := r.URL(client, r.Options.Values)
+ var values url.Values
+ if r.Options != nil {
+ values = r.Options.Values
+ }
+ uri, err := r.URL(client, values)
if err != nil {
return nil, err
}
@@ -105,10 +109,10 @@ func (r Request) do(client *gophercloud.ServiceClient, afterReauth bool) (*http.
return nil, err
}
- req.Header.Set("User-Agent", provider.UserAgent.Join())
- for key, values := range r.Options.Headers {
- req.Header[key] = values
+ for k, v := range r.Headers {
+ req.Header[k] = v
}
+ req.Header.Set("User-Agent", provider.UserAgent.Join())
for key, value := range provider.AuthenticatedHeaders() {
req.Header.Set(key, value)
}