##// END OF EJS Templates
Allow downloading images from servers that don't provice content-length header
neko259 -
r962:405bf307 default
parent child Browse files
Show More
@@ -249,11 +249,14 b' class PostForm(NeboardForm):'
249 response_head = requests.head(url, verify=False)
249 response_head = requests.head(url, verify=False)
250 content_type = response_head.headers['content-type']
250 content_type = response_head.headers['content-type']
251 if content_type in CONTENT_TYPE_IMAGE:
251 if content_type in CONTENT_TYPE_IMAGE:
252 length = int(response_head.headers['content-length'])
252 length_header = response_head.headers.get('content-length')
253 if length > board_settings.MAX_IMAGE_SIZE:
253 # TODO Do something if there is no such header
254 raise forms.ValidationError(
254 if length_header:
255 _('Image must be less than %s bytes')
255 length = int(length_header)
256 % str(board_settings.MAX_IMAGE_SIZE))
256 if length > board_settings.MAX_IMAGE_SIZE:
257 raise forms.ValidationError(
258 _('Image must be less than %s bytes')
259 % str(board_settings.MAX_IMAGE_SIZE))
257
260
258 # Get the actual content into memory
261 # Get the actual content into memory
259 response = requests.get(url, verify=False)
262 response = requests.get(url, verify=False)
@@ -268,6 +271,8 b' class PostForm(NeboardForm):'
268 content_type)
271 content_type)
269 except Exception:
272 except Exception:
270 # Just return non image
273 # Just return non image
274 import traceback
275 traceback.print_exc()
271 pass
276 pass
272
277
273 return img_temp
278 return img_temp
General Comments 0
You need to be logged in to leave comments. Login now