mirror of https://github.com/scrapy/scrapy.git
HttpErrorMiddleware: performance improvement and added support for 'handle_httpstatus_list' request meta key
This commit is contained in:
parent
8c2f62ba9c
commit
2463842acb
|
|
@ -7,6 +7,12 @@ See documentation in docs/ref/spider-middleware.rst
|
|||
class HttpErrorMiddleware(object):
|
||||
|
||||
def process_spider_input(self, response, spider):
|
||||
if not (200 <= response.status < 300 or \
|
||||
response.status in getattr(spider, 'handle_httpstatus_list', [])):
|
||||
return []
|
||||
if 200 <= response.status < 300: # common case
|
||||
return
|
||||
if 'handle_httpstatus_list' in response.request.meta:
|
||||
allowed_statuses = response.request.meta['handle_httpstatus_list']
|
||||
else:
|
||||
allowed_statuses = getattr(spider, 'handle_httpstatus_list', ())
|
||||
if response.status in allowed_statuses:
|
||||
return
|
||||
return []
|
||||
|
|
|
|||
Loading…
Reference in New Issue