Unified · Split
| @@ -12,6 +12,11 @@ module Docs · 11 unmodified lines | ||
| 12 | 12 | body.blank? |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | + def content_length | |
| 16 | + value = headers['Content-Length'] || '0' | |
| 17 | + value.to_i | |
| 18 | + end | |
| 19 | + | |
| 15 | 20 | def mime_type |
| 16 | 21 | headers['Content-Type'] || 'text/plain' |
| 17 | 22 | end |
| @@ -46,6 +46,13 @@ module Docs · 45 unmodified lines | ||
| 46 | 46 | next |
| 47 | 47 | end |
| 48 | 48 | |
| 49 | + size = response.content_length | |
| 50 | + | |
| 51 | + if size > (context[:max_image_size] || DEFAULT_MAX_SIZE) | |
| 52 | + instrument 'too_big.image', url: url, size: size | |
| 53 | + next | |
| 54 | + end | |
| 55 | + | |
| 49 | 56 | image = response.body |
| 50 | 57 | |
| 51 | 58 | unless context[:optimize_images] == false |
| @@ -63,6 +63,17 @@ class DocsResponseTest < MiniTest::Spec · 62 unmodified lines | ||
| 63 | 63 | end |
| 64 | 64 | end |
| 65 | 65 | |
| 66 | + describe "#content_length" do | |
| 67 | + it "returns the content type" do | |
| 68 | + options.headers['Content-Length'] = '188420' | |
| 69 | + assert_equal 188420, response.content_length | |
| 70 | + end | |
| 71 | + | |
| 72 | + it "defaults to 0" do | |
| 73 | + assert_equal 0, response.content_length | |
| 74 | + end | |
| 75 | + end | |
| 76 | + | |
| 66 | 77 | describe "#mime_type" do |
| 67 | 78 | it "returns the content type" do |
| 68 | 79 | options.headers['Content-Type'] = 'type' |