tower-rs / tower-http

HTTP specific Tower utilities.
675 stars 156 forks source link

Optimize encoding selection for compression middleware #471

Closed jplatte closed 6 months ago

jplatte commented 6 months ago

Motivation

I noticed that Encoding::from_headers unnecessarily allocates a Vec for all the supported encodings it finds before selecting the most suitable one of them.

Solution

Change encodings to return an iterator and only collect that iterator where it makes sense.