Add HTTPCompressorWithLevels to customize compression levels
Also add HTTPCompressorWithCustom that take factories.
Solves https://github.com/andybalholm/brotli/issues/55
I'd rather not add the WithCustom function. If the user wants something truly custom, he can always handle the header negotiation himself…
The reason I added that was because in my case I wanted to use the V1 brotli compressor instead of the V2 compressor. (Based on the docs, it sounds like currently the V2 compressor is expected to achieve better results for compression levels >= 2, and since I needed best speed it was unclear if using the V2 compressor was going to be optimal.) All of the other funcs are not public, so re-implementing all of that logic (including detecting whether to use brotli or gzip) would be a waste when it's well done in this package.
Alternatively, another parameter could be added to choose V1 vs V2 compressor, but that seemed to pollute the WithLevel interface a bit. Also, if someone wants to customize other parameters like window size, etc., it would be easier done using a WithCustom interface. What do you think?
If someone wants to customize as far as window size, they should be doing the compression themselves instead of using a convenience function.
But you could definitely make the WithLevels function use V1 for some levels and V2 for others.
Instead of adding a WithCustom function, would you be open instead to making negotiateContentEncoding a public function? There is a lot of useful logic behind that function, and that would give a caller all the tools needed to do whatever custom things they wanted to create their own custom Brotli compressor with the right options, but still not have to replicate all of the logic contained in NegotiateContentEncoding, etc.
NegotiateContentEncoding already is a public function, in github.com/golang/gddo. I copied it into the brotli package to avoid pulling in a large dependency.
I've added HTTPCompressorWithLevel, which has one level parameter, used for both brotli and gzip.