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

Gzip middleware for client #2673

Merged
merged 4 commits into from Jul 2, 2019

Conversation

@balatbn
Copy link

commented Jun 26, 2019

Uses compress from fs2

bsrini added some commits Jun 26, 2019

bsrini
bsrini
private val supportedCompressions =
Seq(ContentCoding.gzip.coding, ContentCoding.deflate.coding).mkString(", ")

def apply[F[_]: Sync](bufferSize: Int = 32 * 1024)(client: Client[F]): Client[F] =

This comment has been minimized.

Copy link
@ChristopherDavenport

ChristopherDavenport Jun 26, 2019

Member

Is a Sync constraint necessary?

This comment has been minimized.

Copy link
@balatbn

balatbn Jun 26, 2019

Author

fs2.compress.gunip requires an F that is RaiseThrowable. Since RaiseThrowable is from fs2, I added Sync here. Can we use any other type instead?

This comment has been minimized.

Copy link
@rossabaker

rossabaker Jun 26, 2019

Member

ApplicativeError?

This comment has been minimized.

Copy link
@balatbn

balatbn Jun 27, 2019

Author

I tried changing it to ApplicativeError. Now, I'm getting missing Bracket error for new Client creation. I'll update PR by changing this to Bracket

This comment has been minimized.

Copy link
@balatbn

balatbn Jun 27, 2019

Author

Updated PR

@rossabaker
Copy link
Member

left a comment

Thanks, this looks like a good start.

response.headers.get(`Content-Encoding`) match {
case Some(header)
if header.contentCoding == ContentCoding.gzip || header.contentCoding == ContentCoding.`x-gzip` =>
response.body.through(fs2.compress.gunzip(bufferSize))

This comment has been minimized.

Copy link
@rossabaker

rossabaker Jun 26, 2019

Member

Should this remove that ContentCoding as well? Similar on the deflate case.

This comment has been minimized.

Copy link
@balatbn

balatbn Jun 27, 2019

Author

I thought it is better not to touch this header as client code can use this to confirm whether response was actually compressed. I can remove this if this is not required.

This comment has been minimized.

Copy link
@rossabaker

rossabaker Jun 28, 2019

Member

I think it's better that we do, because the Content-Coding no longer reflects reality. This is important in case the client is used in a proxy. We should also be sure Content-Length is gone. I can't remember offhand whether withBodyStream takes care of this or not.

This comment has been minimized.

Copy link
@balatbn

balatbn Jun 28, 2019

Author

Changed code to remove both the headers

bsrini
@rossabaker
Copy link
Member

left a comment

Looks good to me once the headers are cleaned up.

response.headers.get(`Content-Encoding`) match {
case Some(header)
if header.contentCoding == ContentCoding.gzip || header.contentCoding == ContentCoding.`x-gzip` =>
response.body.through(fs2.compress.gunzip(bufferSize))

This comment has been minimized.

Copy link
@rossabaker

rossabaker Jun 28, 2019

Member

I think it's better that we do, because the Content-Coding no longer reflects reality. This is important in case the client is used in a proxy. We should also be sure Content-Length is gone. I can't remember offhand whether withBodyStream takes care of this or not.

@ChristopherDavenport ChristopherDavenport merged commit de2dfcb into http4s:master Jul 2, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

rossabaker added a commit to rossabaker/http4s that referenced this pull request Jul 3, 2019

rossabaker added a commit that referenced this pull request Jul 3, 2019

Merge pull request #2689 from rossabaker/backport-2673
Backport #2673: Gzip middleware for client

@balatbn balatbn deleted the balatbn:clientgzip branch Jul 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.