Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto gzip will fail when Content-Encoding is gzip and content-length is zero #164

Closed
Jack47 opened this issue Jun 26, 2018 · 1 comment
Closed
Assignees
Labels

Comments

@Jack47
Copy link
Contributor

Jack47 commented Jun 26, 2018

there are some cases that the response's content-length is zero, in this case the below code will return err because failure of gzip.NewReader.
https://github.com/go-resty/resty/blob/master/client.go#L804-L812

		if strings.EqualFold(resp.Header.Get(hdrContentEncodingKey), "gzip") {
			if _, ok := body.(*gzip.Reader); !ok {
				body, err = gzip.NewReader(body)
				if err != nil {
					return response, err
				}
				defer closeq(body)
			}
		}

gzip.NewReader(body) will try to read the gzip header, so the call will fail.

I added some test cases and fixed this locally, I would like to pull a request to fix this if needed.

Jack47 added a commit to Jack47/resty that referenced this issue Jun 26, 2018
@Jack47 Jack47 changed the title auto gzip will fail when Content-Encoding is gzip but content-length is zero auto gzip will fail when Content-Encoding is gzip and content-length is zero Jun 26, 2018
jeevatkm pushed a commit that referenced this issue Jun 26, 2018
* don't use gzipped reader when response content-length is zero
* add test case for auto gzip response
         1. gzipped empty response, content-length will not be empty, because of gzip header
         2. no gzipped body and content-length is zero
@jeevatkm jeevatkm added the bug label Jun 26, 2018
@jeevatkm jeevatkm added this to the v1.7 Milestone milestone Jun 26, 2018
@jeevatkm
Copy link
Member

@Jack47 Thank you for PR and addressing edge use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants