Repository: beatlabs/patron
Pull request #307 (2020-12-09 09:29:25)

Fix identity accept encoding
<!--
Thanks for taking precious time for making a PR.

Before creating a pull request, please make sure:
- Your PR solves one problem for which a issue exist and a solution has been discussed
- You have read the guide for contributing
  - See https://github.com/beatlabs/patron/blob/master/README.md#how-to-contribute
- You signed all your commits (otherwise we won't be able to merge the PR)
  - See https://github.com/beatlabs/patron/blob/master/SIGNYOURWORK.md
- You added unit tests for the new functionality
- You mention in the PR description which issue it is addressing, e.g. "Resolves #123"
-->

## Which problem is this PR solving?

Follow-up bug fix for https://github.com/beatlabs/patron/issues/300 and https://github.com/beatlabs/patron/issues/301

## Short description of the changes

`identity` Accept-Encoding sneaked in untested and thus broken.


codecov[bot]: # [Codecov](https://codecov.io/gh/beatlabs/patron/pull/307?src=pr&el=h1) Report
> Merging [#307](https://codecov.io/gh/beatlabs/patron/pull/307?src=pr&el=desc) (945aea1) into [master](https://codecov.io/gh/beatlabs/patron/commit/bd955b14104488136b4148db9c8021ab71676411?el=desc) (bd955b1) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/beatlabs/patron/pull/307/graphs/tree.svg?width=650&height=150&src=pr&token=sxY15rXW1X)](https://codecov.io/gh/beatlabs/patron/pull/307?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #307   +/-   ##
=======================================
  Coverage   72.74%   72.74%           
=======================================
  Files          61       61           
  Lines        3332     3332           
=======================================
  Hits         2424     2424           
  Misses        815      815           
  Partials       93       93           
```


| [Impacted Files](https://codecov.io/gh/beatlabs/patron/pull/307?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [component/http/middleware.go](https://codecov.io/gh/beatlabs/patron/pull/307/diff?src=pr&el=tree#diff-Y29tcG9uZW50L2h0dHAvbWlkZGxld2FyZS5nbw==) | `88.48% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/beatlabs/patron/pull/307?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/beatlabs/patron/pull/307?src=pr&el=footer). Last update [bd955b1...945aea1](https://codecov.io/gh/beatlabs/patron/pull/307?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/component/http/middleware.go b/component/http/middleware.go
index 98016fd46..0c43d12d1 100644
--- a/component/http/middleware.go
+++ b/component/http/middleware.go
@@ -200,7 +200,7 @@ func addWithWeight(mapWeighted map[float64]string, weight float64, algorithm str
 }
 
 func notSupportedCompression(algorithm string) bool {
-	return gzipHeader != algorithm && deflateHeader != algorithm && anythingHeader != algorithm
+	return gzipHeader != algorithm && deflateHeader != algorithm && anythingHeader != algorithm && identityHeader != algorithm
 }
 
 // When not present, the default value is 1 according to https://developer.mozilla.org/en-US/docs/Glossary/Quality_values


Test patch:
diff --git a/component/http/middleware_test.go b/component/http/middleware_test.go
index 70654e81c..3a1d17d0b 100644
--- a/component/http/middleware_test.go
+++ b/component/http/middleware_test.go
@@ -324,6 +324,8 @@ func TestNewCompressionMiddleware_Headers(t *testing.T) {
 		"invalid, deflate, *": {cm: middleware, statusCode: http.StatusOK, encodingExpected: deflateHeader},
 		"invalid":             {cm: middleware, statusCode: http.StatusNotAcceptable, encodingExpected: ""},
 		"invalid, *":          {cm: middleware, statusCode: http.StatusOK, encodingExpected: ""},
+		"identity":            {cm: middleware, statusCode: http.StatusOK, encodingExpected: identityHeader},
+		"gzip, identity":      {cm: middleware, statusCode: http.StatusOK, encodingExpected: gzipHeader},
 		"*":                   {cm: middleware, statusCode: http.StatusOK, encodingExpected: ""},
 		"":                    {cm: middleware, statusCode: http.StatusOK, encodingExpected: identityHeader},
 		"not present":         {cm: middleware, statusCode: http.StatusOK, encodingExpected: identityHeader},