swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.04k stars 390 forks source link

Add Gzip support on response chunk mode #456

Closed hezachary closed 3 years ago

hezachary commented 3 years ago

Swoole does not support compress on chunk mode, related document: https://wiki.swoole.com/#/http_server?id=http_compression

The patch provide gzip for such needs.

A example is AWS load balance in many cases can replace server like apache or nginx. However, ALB does not provide compression. Once swoole in chunk mode, there almost no other choice but to add a web server in between.

  1. The patch checks Laravel/Lumen response header to avoid double compression
  2. Only gzip when client side provide "accept-encoding" header with gzip option
  3. Only gzip when Swoole config shows http_compression = true
  4. Also, it checks zlib gzencode is installed
coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.3%) to 68.095% when pulling 2911def74d9f9f9e138c53748f769cc352b3a2a3 on hezachary:master into 714cb6de964f1249ada5590832d89f0ba6526fe2 on swooletw:master.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+1.6%) to 69.948% when pulling b2da17030c05710112777e1a992b1ff2d768b820 on hezachary:master into 714cb6de964f1249ada5590832d89f0ba6526fe2 on swooletw:master.

RodrigoGalter commented 3 years ago

Any idea when this will be approved?

Arkanius commented 3 years ago

I'm still reviewing it

hezachary commented 3 years ago

I will add more test case to increase coverage today, at least for my code.

hezachary commented 3 years ago

With the new test case, coverage for SwooleTW\Http\Transformers/\Response Screen Shot 2020-12-17 at 1 43 47 pm

hezachary commented 3 years ago

Is there anything I can do to improve the PR to help you @Arkanius approve it?

Arkanius commented 3 years ago

Thank you @hezachary ! I think that is ok! I'm planning to release it at this week

Arkanius commented 3 years ago

@hezachary it's now release as v2.7.0

Thanks for your support!