aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--account.go1
-rw-r--r--container.go2
-rw-r--r--object.go1
-rw-r--r--request.go9
4 files changed, 12 insertions, 1 deletions
diff --git a/account.go b/account.go
index 8193cb6..bbca9c5 100644
--- a/account.go
+++ b/account.go
@@ -143,6 +143,7 @@ func (a *Account) Create(headers AccountHeaders, opts *RequestOptions) error {
Headers: headersToHTTP(headers),
Options: opts,
ExpectStatusCodes: []int{201, 202},
+ DrainResponseBody: true,
}.Do(a.client)
if err == nil {
a.Invalidate()
diff --git a/container.go b/container.go
index 7f5097f..f075d15 100644
--- a/container.go
+++ b/container.go
@@ -123,6 +123,7 @@ func (c *Container) Create(headers ContainerHeaders, opts *RequestOptions) error
Headers: headersToHTTP(headers),
Options: opts,
ExpectStatusCodes: []int{201, 202},
+ DrainResponseBody: true,
}.Do(c.a.client)
if err == nil {
c.Invalidate()
@@ -170,6 +171,7 @@ func (c *Container) EnsureExists() (*Container, error) {
Method: "PUT",
ContainerName: c.name,
ExpectStatusCodes: []int{201, 202},
+ DrainResponseBody: true,
}.Do(c.a.client)
return c, err
}
diff --git a/object.go b/object.go
index c2f6986..3f1ebe0 100644
--- a/object.go
+++ b/object.go
@@ -143,6 +143,7 @@ func (o *Object) Upload(content io.Reader, headers ObjectHeaders, opts *RequestO
Options: opts,
Body: content,
ExpectStatusCodes: []int{201},
+ DrainResponseBody: true,
}.Do(o.c.a.client)
if err == nil {
o.Invalidate()
diff --git a/request.go b/request.go
index 1128a00..9087115 100644
--- a/request.go
+++ b/request.go
@@ -70,6 +70,9 @@ type Request struct {
//ExpectStatusCodes can be left empty to disable this check, otherwise
//schwift.UnexpectedStatusCodeError may be returned.
ExpectStatusCodes []int
+ //DrainResponseBody can be set if the caller is not interested in the
+ //response body. This is implied for Response.StatusCode == 204.
+ DrainResponseBody bool
}
//URL returns the full URL for this request.
@@ -144,7 +147,11 @@ func (r Request) do(client *gophercloud.ServiceClient, afterReauth bool) (*http.
}
for _, code := range r.ExpectStatusCodes {
if code == resp.StatusCode {
- return resp, nil
+ var err error
+ if r.DrainResponseBody || resp.StatusCode == 204 {
+ err = drainResponseBody(resp)
+ }
+ return resp, err
}
}