Coverage for src/icap_request_handler.py : 87%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim:ts=3:sw=3:expandtab
# NoModICAPFilter is loaded dynamically. Without this import, # globals() does not see it. But, pylint complains. Disable pylint error. # pylint: disable=unused-import
"""Subclasses pyicap implementation and invoke icap_filter chain
Builds a icap_filter chain and invokes the filters in the specified order. If any icap_filter decides to handle the icap_message, it needs to set the icap_response. All subsequent icap_filters will not see the icap transaction. """ close_connection=False): """Initializes the icap_filter chain"""
except Exception: raise NameError("Class %s is not defined" % cls)
# Order specific. Will be created with self.config and self.tenant_config
for klass in reqmod_classes] for klass in respmod_classes]
def read_preview(self): """Helper function to read icap preview data"""
"""Sets the ICAP response's status line and response code""" else: super(ICAPRequestHandler, self).set_enc_status(status)
def send_icap_response(self, icap_resp, http_resp): """Write the icap response to squid"""
yield http_resp.body(self.write_chunk) else:
# Finally flush the connection to ensure there is no data left. # In the event of a transfer error the Squid <-> ICAP connection # MUST be flushed or data will be left and interpreted as a new # ICAP REQ in the connection. # Flush is not done at this point of error to prevent a request with no # content-length header from sending an unlimited amount of data. # Closing the client <-> squid connection by sending a valid ICAP # response first, will close the squid <-> upstream server connection, # and therefore only leave a finite number of bytes to flush. # By this point the ICAP response will have completed (successful or # not), so the flush can be performed without getting stuck in an # infinite loop.
def icap_options(self): """Handles ICAP OPTIONS request on behalf of all icap_filters"""
def invoke_filters(self, filters, mod_type): """On REQMOD or RESPMOD requests, invokes the icap_filters"""
else:
'mod_type': mod_type, 'status_code': icap_resp.status_code}, event='icap-mod-response')
logger.info({'status_code': icap_resp.status_code}, event='unexpected-icap-mod-response')
logger.info({'mod_type': mod_type}, event='no-icap-mod-response-any-filter') yield self.no_adaptation_required() # The stream close error is raised again so that icap_connection # can get out of the infinite loop. except Exception as ex: logger.exception({'error': ex, 'mod_type': mod_type}, event='icap_request_handler_error') try: # Give 1 last try to send no_adaptation response so that squid does # not flag this transaction as faulty. If squid sees too many faulty # transactions, it will take out the icap_server for a while (a few # minutes). yield self.no_adaptation_required() except Exception: pass
def icap_reqmod(self): """Handles REQMOD icap message"""
def icap_respmod(self): """Handles RESPMOD icap message""" |