def _create_response(self, flow): response = Response( status_code=flow.response.status_code, reason=flow.response.reason, headers=[(k, v) for k, v in flow.response.headers.items(multi=True)], body=flow.response.raw_content, ) cert = flow.server_conn.cert if cert is not None: response.cert = dict( subject=cert.subject, serial=cert.serial, key=cert.keyinfo, signature_algorithm=cert.x509.get_signature_algorithm(), expired=cert.has_expired, issuer=cert.issuer, notbefore=cert.notbefore, notafter=cert.notafter, organization=cert.organization, cn=cert.cn, altnames=cert.altnames, ) return response
def response(self, flow): # Make any modifications to the response # DEPRECATED. This will be replaced by response_interceptor self.proxy.modifier.modify_response(flow.response, flow.request) if not hasattr(flow.request, 'id'): # Request was not stored return # Convert the mitmproxy specific response to one of our responses # for handling. response = Response( status_code=flow.response.status_code, reason=flow.response.reason, headers=[(k, v) for k, v in flow.response.headers.items()], body=flow.response.raw_content ) # Call the response interceptor if set if self.proxy.response_interceptor is not None: self.proxy.response_interceptor(self._create_request(flow, response), response) flow.response.status_code = response.status_code flow.response.reason = response.reason flow.response.headers = self._to_headers_obj(response.headers) flow.response.raw_content = response.body log.info('Capturing response: %s %s %s', flow.request.url, response.status_code, response.reason) self.proxy.storage.save_response(flow.request.id, response)
def _create_response(self, body=b''): headers = [('Content-Type', 'application/json'), ('Content-Length', '500')] return Response(status_code=200, reason='OK', headers=headers, body=body)
def _create_response(self, body=None): response = Response(status_code=200, reason='OK', headers=[ ('Content-Type', 'application/json'), ('Content-Length', '120'), ], body=body) return response
def _create_response(self, flow): response = Response( status_code=flow.response.status_code, reason=flow.response.reason, headers=[(k, v) for k, v in flow.response.headers.items()], body=flow.response.raw_content ) cert = flow.server_conn.cert if cert is not None: response.cert = dict( subject=cert.subject, serial=cert.serial, key=cert.keyinfo, signature_algorithm=cert.x509.get_signature_algorithm(), expired=cert.has_expired, issuer=cert.issuer ) return response