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

fix: Double compression. #1714

Merged
merged 1 commit into from
Jun 14, 2017
Merged

fix: Double compression. #1714

merged 1 commit into from
Jun 14, 2017

Conversation

ldez
Copy link
Contributor

@ldez ldez commented Jun 7, 2017

Description

Don't compress when Content-Encoding header is already present.

Fixes #1060

@ldez ldez added this to the 1.3 milestone Jun 7, 2017
@ldez ldez changed the base branch from master to v1.3 June 7, 2017 09:54
@ldez ldez force-pushed the fix/double-gzip branch 2 times, most recently from 85eb873 to 1c8fd24 Compare June 7, 2017 18:25

func isEncoded(headers http.Header) bool {
header := headers.Get(contentEncodingHeader)
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add this link here? I suppose it's to reference what constitutes an encoding?

If so, could we add an explaining comment? Something like "According to http://..., content is encoded if ...".

assert.Equal(t, acceptEncodingHeader, rw.Header().Get(varyHeader))

if bytes.Compare(rw.Body.Bytes(), baseBody) == 0 {
t.Errorf("got %v,\n expected a compressed body.", rw.Body.Bytes())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixture of testing and testify doesn't seem ideal. How about

assert.True(t, bytes.Compare(rw.Body.Bytes(), baseBody) == 0)

Copy link
Contributor Author

@ldez ldez Jun 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If want to see the diff and if I do that I just see: false is different of true.
Testify doesn't provide assert.NotEqualValues, this is why I do that.
It's just a pragmatic approach

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what the msgAndArgs final arguments to every testify assertion method are supposed to be used for. From the docs:

Every assertion function also takes an optional string message as the final argument, allowing custom error messages to be appended to the message the assertion method outputs.

Copy link
Contributor Author

@ldez ldez Jun 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but I will see this:

Expected: True
Actual: False
Message: got XXX...
expected a compressed body.

And I don't think it's a good test output.

I prefer mix stdlib and Testify, it's a better compromise for me.

assert.Equal(t, "", rw.Header().Get(varyHeader))

assert.EqualValues(t, rw.Body.Bytes(), baseBody)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test seems structurally identical to TestShouldCompressWhenNoContentEncodingHeader. How about combining both in a table-driven test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really want to do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Copy link
Contributor Author

@ldez ldez Jun 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it's not my way to test:

  • I follow a Kent Beck rule about triangulation: I begin to thinking about a possible factorization if I repeat 3 times the same thing (the number 3, it's my limit, not a KB limit, but it's a very classic number for that with TDD)
  • the tests are more flexible and more resistant to changes of the implementation.
  • each test is independent and can be "recycle" (it's a testing strategy)
  • the code in the test provide some limitation to be clearly factorize. (readability)
  • table-driven test are not the only way to write good tests: each test case are different and we can use a lot of technique or approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm sorry, I find most of these arguments too general and abstract.

The flexibility point sounds like a bet into the future that only some parts of the tests will need to be adjusted. It could just as well be that a part common to both tests will need to be changed, so separate tests could be more costly. We don't know what part might change; we do know though that we can save lines and improve readability by taking a table-driven approach now, possibly changing again in the future.

So I don't agree but I neither bother too much as it's just about two tests. :-)

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ldez
LGTM

@ldez ldez force-pushed the fix/double-gzip branch from 2cbf8b7 to 1aad098 Compare June 14, 2017 17:53
@ldez ldez merged commit d87c4d8 into traefik:v1.3 Jun 14, 2017
@ldez ldez deleted the fix/double-gzip branch June 14, 2017 19:13
@tkizm1
Copy link

tkizm1 commented Jun 20, 2017

still not work as expected
content-encoding:gzip
is not work
Content-Encoding is the only way?

@kevinjqiu
Copy link

I'm expericing this issue too with 1.3.3. Bug report here #1851

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

Successfully merging this pull request may close these issues.

5 participants