Пример #1
0
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
Пример #2
0
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,
    )
Пример #3
0
 def get_headers(self, environ):
     headers = HTTPException.get_headers(self, environ)
     if self.valid_methods:
         headers.append(('Allow', ', '.join(self.valid_methods)))
     return headers
Пример #4
0
 def get_headers(self):
     return HTTPException.get_headers(self) + [('Location', self.location)]
Пример #5
0
 def get_headers(self, environ):
     headers = HTTPException.get_headers(self, environ)
     headers.append(('WWW-Authenticate', 'Basic realm="MCM API"'))
     return headers
Пример #6
0
 def get_headers(self, environ):
     headers = HTTPException.get_headers(self, environ)
     if self.valid_methods:
         headers.append(('Allow', ', '.join(self.valid_methods)))
     return headers
Пример #7
0
 def get_headers(self, environ):
     headers = HTTPException.get_headers(self, environ)
     headers.append(('WWW-Authenticate', 'Basic realm="MCM API"'))
     return headers