def http_exception_to_response(e: HTTPException): """Convert a werkzeug HTTP exception to a requests.Response object""" response = Response() response.status_code = e.code response.headers.update(dict(e.get_headers())) body = e.get_body() response.headers["Content-Length"] = str(len(str(body or ""))) response._content = body return response
def _respond_http_exception( start_response: StartResponse, exception: HTTPException ) -> Iterable[bytes]: assert exception.code is not None status = HTTPStatus(exception.code) html = http_status_page(status, message=exception.description or "") headers = [ h for h in exception.get_headers() if h[0].lower() != "content-type" ] return respond_with_html( start_response, html, status=status, extra_headers=headers, )
def get_headers(self, environ): headers = HTTPException.get_headers(self, environ) if self.valid_methods: headers.append(('Allow', ', '.join(self.valid_methods))) return headers
def get_headers(self): return HTTPException.get_headers(self) + [('Location', self.location)]
def get_headers(self, environ): headers = HTTPException.get_headers(self, environ) headers.append(('WWW-Authenticate', 'Basic realm="MCM API"')) return headers