コード例 #1
0
ファイル: content_type.py プロジェクト: PKRoma/pump
 def wrapped_app(req):
   resp = app(req)
   if not resp or resp.get("headers", {}).get("content_type"):
     return resp
   mime_type, _ = mimetypes.guess_type(req["uri"])
   return response.with_content_type(resp,
     mime_type or "application/octet-stream")
コード例 #2
0
ファイル: content_type.py プロジェクト: trb116/pythonanalyzer
 def wrapped_app(req):
     resp = app(req)
     if not resp or resp.get("headers", {}).get("content_type"):
         return resp
     mime_type, _ = mimetypes.guess_type(req["uri"])
     return response.with_content_type(
         resp, mime_type or "application/octet-stream")
コード例 #3
0
ファイル: response.py プロジェクト: adeel/picasso
def render(response, request):
  if not response:
    return

  if not isinstance(response, dict):
    # If the response is a function, call it and render the result.
    if callable(response):
      return render(
        response(request, **request.get("route_params", {})), request)
    response = with_body(response)

  response["body"] = _render_body(response.get("body"), request)
  # Default content_type is text/html.
  if not response.get("headers", {}).get("content_type"):
    response = with_content_type(response, "text/html")

  return response