示例#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
文件: auth.py 项目: diazona/Modulo
 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