Commit 5cfbb5b3 authored by Mitar's avatar Mitar
Browse files

Support X-Goog-Stored-Content-Length.

parent 7b02592b
Pipeline #443904200 passed with stages
in 2 minutes and 10 seconds
......@@ -119,13 +119,16 @@ func (d *RetryableResponse) start() errors.E {
body, _ := io.ReadAll(resp.Body)
return errors.Errorf("bad response status (%s): %s", resp.Status, strings.TrimSpace(string(body)))
}
lengthStr := resp.Header.Get("Content-Length")
if lengthStr == "" {
return errors.Errorf("missing Content-Length header in response")
length := resp.ContentLength
if length == -1 {
// Check GCP header. GCP omits Content-Length header when response is Content-Encoding compressed.
l, err := strconv.ParseInt(resp.Header.Get("X-Goog-Stored-Content-Length"), 10, 64) //nolint:gomnd
if err == nil {
length = l
}
}
length, err := strconv.ParseInt(lengthStr, 10, 64) //nolint:gomnd
if err != nil {
return errors.WithStack(err)
if length == -1 {
return errors.Errorf("missing Content-Length header in response")
}
size := d.Size()
......
......@@ -37,7 +37,7 @@ func TestRetryableResponseSimple(t *testing.T) {
require.NotNil(t, res)
defer res.Close()
assert.Equal(t, "14", res.Header.Get("Content-Length"))
assert.Equal(t, int64(14), res.ContentLength)
assert.Equal(t, int64(14), res.Size())
response, err := io.ReadAll(res)
......@@ -83,7 +83,7 @@ func TestRetryableResponseRetry(t *testing.T) {
require.NotNil(t, res)
defer res.Close()
assert.Equal(t, "14", res.Header.Get("Content-Length"))
assert.Equal(t, int64(14), res.ContentLength)
assert.Equal(t, int64(14), res.Size())
data, err := io.ReadAll(res)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment