thoas / picfit

An image resizing server written in Go
http://bit.ly/1E7rSoi
MIT License
2.1k stars 173 forks source link

Handle redirections #44

Open dehy opened 8 years ago

dehy commented 8 years ago

Actually, the server fails if it find redirections. It would be great if we could configure the number of max redirections to follow before failure.

picfit-1 | 2016-02-24T09:36:38.539447359Z time="2016-02-24T09:36:38Z" level="info" msg="started handling request" method="GET" remote="172.17.0.13:40641" request="/display?url=http%3A%2F%2Fcoverartarchive.org%2Frelease%2F1919faf1-61d8-4741-a530-4afbaed125c9%2F6972823009.jpg&w=512&h=512&op=resize&fmt=jpg" 
picfit-1 | 2016-02-24T09:36:38.539841822Z time="2016-02-24T09:36:38Z" level="info" msg="Key cdaaa10ccbf85f4718b300135e84671b not found in kvstore"
picfit-1 | 2016-02-24T09:36:38.872947671Z time="2016-02-24T09:36:38Z" level="info" msg="PANIC: Get http://archive.org/download/mbid-1919faf1-61d8-4741-a530-4afbaed125c9/mbid-1919faf1-61d8-4741-a530-4afbaed125c9-6972823009.jpg: Error redirecting. MaxRedirects reached\ngoroutine 416 [running]:\ngithub.com/thoas/picfit/middleware.(*Recovery).ServeHTTP.func1(0x7fa84f6fb278, 0xc820254600, 0xc82019a280, 0xc8202261c0)\n\t/go/src/github.com/thoas/picfit/middleware/middleware.go:36 +0x10a\npanic(0x9866a0, 0xc82019a2c0)\n\t/usr/local/go/src/runtime/panic.go:426 +0x4e9\ngithub.com/thoas/picfit/application.glob.func4(0x7fa84f6fb278, 0xc820254600, 0xc82015e1e0, 0xc8200981b0)\n\t/go/src/github.com/thoas/picfit/application/handlers.go:22 +0x86\ngithub.com/thoas/picfit/application.(*Application).ServeHTTP.func1(0x7fa84f6fb278, 0xc820254600, 0xc8202261c0)\n\t/go/src/github.com/thoas/picfit/application/application.go:114 +0x2b6\nnet/http.HandlerFunc.ServeHTTP(0xc82012f720, 0x7fa84f6fb278, 0xc820254600, 0xc8202261c0)\n\t/usr/local/gpicfit-1 | 2016-02-24T09:36:48.710753471Z time="2016-02-24T09:36:48Z" level="info" msg="Started GET /display" 
thoas commented 8 years ago

Good idea :+1: