barnacs / compy

HTTP/HTTPS compression proxy
ISC License
206 stars 34 forks source link

fix the content-type mismatch problem #70

Open Web-Distortion opened 2 years ago

Web-Distortion commented 2 years ago

We notice that Compy judge the content type based on the content-type field in the http response header. It is possible to cause failure (especially when performing decompression) when the content-type field does not match the real type of web content. A better way to recognize the real content type is to use the file format magic code in the file header. To this end, we should get the response.body first (from line 216 to line 225 in ./proxy/proxy.go) 1.To support precise recognition of JPEG files, we can check whether the first 2 bytes in response.body equals to 0xffd8 (from line 230 to line 232 in ./proxy/proxy.go). 2.To support precise recognition of PNG files, we can check whether the first 3 bytes in response.body equals to 0x474946 (from line 237 to line 239 in ./proxy/proxy.go). 3.To support precise recognition of gif files, we can check whether the first 7 bytes in response.body equals to 0x89504e470d0a1a (from line 233 to line 236 in ./proxy/proxy.go). In addition, we fix a syntax error (on line 144).

Web-Distortion commented 2 years ago

Needs some kind of test.

Thanks for your detailed comments! We have replied to your comments in detail below and modified the code accordingly. Please check :)