cactus / go-camo

A secure image proxy server
MIT License
254 stars 48 forks source link

Video content not supported in Safari #36

Closed digitalmoksha closed 5 years ago

digitalmoksha commented 5 years ago

Specifications

Version: go-camo 1.1.4-9-g4369d52 (go1.12.4,gc-amd64) Platform: macOS 10.14.5

Expected Behavior

Visiting a proxied video in Safari should display properly

Actual Behavior

The video does not display, we always get a write: broken pipe. Here is the log output:

time="2019-07-24T18:26:07.030372000-05:00" level="D" msg="client request" req="&{GET /694bea43b037fdf93ef5efc6c9ab6c2fe7f2ba2f/687474703a2f2f636c6970732e766f727761657274732d676d62682e64652f6269675f6275636b5f62756e6e792e6d7034 HTTP/1.1 1 1 map[Accept:[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8] Accept-Encoding:[gzip, deflate] Accept-Language:[en-us] Connection:[keep-alive] Upgrade-Insecure-Requests:[1] User-Agent:[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15]] {} <nil> 0 [] false localhost:8080 map[] map[] <nil> map[] [::1]:61038 /694bea43b037fdf93ef5efc6c9ab6c2fe7f2ba2f/687474703a2f2f636c6970732e766f727761657274732d676d62682e64652f6269675f6275636b5f62756e6e792e6d7034 <nil> <nil> <nil> 0xc000192ec0}"

time="2019-07-24T18:26:07.030477000-05:00" level="D" msg="signed client url" url="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"

time="2019-07-24T18:26:07.067896000-05:00" level="D" msg="built outgoing request" req="&{GET http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 HTTP/1.1 1 1 map[Accept:[image/*, video/*] Accept-Language:[en-us] User-Agent:[go-camo] Via:[go-camo]] <nil> <nil> 0 [] false clips.vorwaerts-gmbh.de map[] map[] <nil> map[]   <nil> <nil> <nil> <nil>}"

time="2019-07-24T18:26:07.161521000-05:00" level="D" msg="response from upstream" resp="&{200 OK 200 HTTP/1.1 1 1 map[Accept-Ranges:[bytes] Age:[15970] Cache-Control:[public, max-age=31536000] Cf-Cache-Status:[HIT] Cf-Ray:[4fb9a83eadcc5847-DFW] Connection:[keep-alive] Content-Length:[5510872] Content-Type:[video/mp4] Date:[Wed, 24 Jul 2019 23:26:07 GMT] Etag:[\"5416d8-47f21fa7d3300\"] Expires:[Thu, 23 Jul 2020 23:26:07 GMT] Last-Modified:[Tue, 09 Feb 2010 02:50:20 GMT] Server:[cloudflare] Set-Cookie:[__cfduid=d49c393732047191c856d72870210062c1564010767; expires=Thu, 23-Jul-20 23:26:07 GMT; path=/; domain=.vorwaerts-gmbh.de; HttpOnly]] 0xc0001336a0 5510872 [] false false map[] 0xc000195600 <nil>}"

time="2019-07-24T18:26:07.240210000-05:00" level="D" msg="error writing response" err="write tcp [::1]:8080->[::1]:61038: write: broken pipe"

time="2019-07-24T18:26:07.319530000-05:00" level="D" msg="client request" req="&{GET /694bea43b037fdf93ef5efc6c9ab6c2fe7f2ba2f/687474703a2f2f636c6970732e766f727761657274732d676d62682e64652f6269675f6275636b5f62756e6e792e6d7034 HTTP/1.1 1 1 map[Accept:[*/*] Accept-Encoding:[identity] Accept-Language:[en-us] Connection:[keep-alive] Range:[bytes=0-1] Referer:[http://localhost:8080/694bea43b037fdf93ef5efc6c9ab6c2fe7f2ba2f/687474703a2f2f636c6970732e766f727761657274732d676d62682e64652f6269675f6275636b5f62756e6e792e6d7034] User-Agent:[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15] X-Playback-Session-Id:[DB7C49DD-C663-4A25-8E83-B309A6B59029]] {} <nil> 0 [] false localhost:8080 map[] map[] <nil> map[] [::1]:61043 /694bea43b037fdf93ef5efc6c9ab6c2fe7f2ba2f/687474703a2f2f636c6970732e766f727761657274732d676d62682e64652f6269675f6275636b5f62756e6e792e6d7034 <nil> <nil> <nil> 0xc00025e880}"

time="2019-07-24T18:26:07.319626000-05:00" level="D" msg="signed client url" url="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"

time="2019-07-24T18:26:07.359092000-05:00" level="D" msg="built outgoing request" req="&{GET http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 HTTP/1.1 1 1 map[Accept:[image/*, video/*] Accept-Language:[en-us] User-Agent:[go-camo] Via:[go-camo]] <nil> <nil> 0 [] false clips.vorwaerts-gmbh.de map[] map[] <nil> map[]   <nil> <nil> <nil> <nil>}"

time="2019-07-24T18:26:07.454661000-05:00" level="D" msg="response from upstream" resp="&{200 OK 200 HTTP/1.1 1 1 map[Accept-Ranges:[bytes] Age:[15970] Cache-Control:[public, max-age=31536000] Cf-Cache-Status:[HIT] Cf-Ray:[4fb9a8408948d266-DFW] Connection:[keep-alive] Content-Length:[5510872] Content-Type:[video/mp4] Date:[Wed, 24 Jul 2019 23:26:07 GMT] Etag:[\"5416d8-47f21fa7d3300\"] Expires:[Thu, 23 Jul 2020 23:26:07 GMT] Last-Modified:[Tue, 09 Feb 2010 02:50:20 GMT] Server:[cloudflare] Set-Cookie:[__cfduid=dfe12ec4a2315005f34afeb93d96682491564010767; expires=Thu, 23-Jul-20 23:26:07 GMT; path=/; domain=.vorwaerts-gmbh.de; HttpOnly]] 0xc000133b00 5510872 [] false false map[] 0xc000195900 <nil>}"

time="2019-07-24T18:26:07.458221000-05:00" level="D" msg="error writing response" err="write tcp [::1]:8080->[::1]:61043: write: broken pipe"

Steps to reproduce

Visit a proxied URL, such as http://mirrors.standaloneinstaller.com/video-sample/small.mp4. Safari will be unable to show the video. Chrome and Firefox can (as long as the -H "Content-Security-Policy: media-src 'self'" option is used).

The problem seems to stem from Safari requiring support for byte ranges. You can take a look at Configuring Your Server. This talks about iOS but it's the same for safari on macOS.

I'm able to get it working by adding

    "Accept-Ranges":    true,
    "Content-Length": true,
    "Content-Range":  true,

to ValidRespHeaders and

    "Range": true,

to ValidReqHeaders.

We also have to allow the 206 status code.

I'll try to get a PR submitted, though my Go skills are minimal right now.

dropwhile commented 5 years ago

Thanks for the clear issue description and PR. 👍

dropwhile commented 5 years ago

Should be resolved in master, as of 8bf49a36707d808b180d923206ea3d0260a5bbf3

digitalmoksha commented 5 years ago

Thanks @cactus, really appreciate it! Any possibility of getting it cut into a release, as it will get rolled into production.

dropwhile commented 5 years ago

sure. no problem.

dropwhile commented 5 years ago

published release binaries here 👍