Show information about available resources.

        .. versionadded:: 0.5.7
            Content-Type check

        :return django.http.HttpResponse
334191
def map_view(self, request):
        
        self.update_urls(request)
        resource_info = {
            "resources": [{
                "id": index + 1,
                "href": "{}/{}".format(self.api_url, resource_name),
            } for index, (resource_name, resource) in enumerate(
                sorted(self.resource_map.items()))
                if not resource.Meta.authenticators or
                resource.authenticate(request) is not None
            ]
        }
        response = json.dumps(resource_info)
        return HttpResponse(response, content_type="application/vnd.api+json")
861691
def available(self, context):
	
		
		
		try:
			if self.__available is None:
				encoded_name = urllib.parse.quote_plus(self.__name)
				status_code, msg = self.__endpoint.get(
					"/resources/custom-resource/{}".format(encoded_name)
				)
				self.__available = status_code == 200
		except:
			self.__available = False
			
		return self.__available
1015309
def _get_response(**kwargs):
    
    if 'code' not in kwargs:
        kwargs['code'] = 200
    if 'headers' not in kwargs:
        kwargs['headers'] = dict()
    if 'version' not in kwargs:
        kwargs['version'] = 'HTTP/1.1'

    return dict(**kwargs)
25241
def get_server_info(self):
        
        response = self.get_proto(path='')
        message = rest_pb2.GetApiOverviewResponse()
        message.ParseFromString(response.content)
        return ServerInfo(message)
912610
def documentation(self, request):
        
        self.update_urls(request)
        context = {
            "resources": sorted(self.resource_map.items())
        }
        return render(request, "jsonapi/index.html", context)
752514
def _http_response(self, url, method, data=None, **kwargs):
        
        header = {'content-type': 'application/json'}

        if data:
            data = json.dumps(data)
        path = url.format(**kwargs)
        logger.debug("%s %s", method.__name__.upper(), path)
        response = method(self.host + path,
                          data=data, headers=header, **self.method_kwargs)
        logger.debug("%s %s", response.status_code, response.reason)
        response.raise_for_status()

        return response
397517
def render_to_response(self, context, **response_kwargs):
        
        return HttpResponse(json.dumps(context, cls=JSON_ENCODER), 
                            content_type='application/json',
                            **response_kwargs)
405001
def model_resources(self):
        

        response = jsonify({
            'apiVersion': '0.1',
            'swaggerVersion': '1.1',
            'basePath': '%s%s' % (self.base_uri(), self.api.url_prefix),
            'apis': self.get_model_resources()
        })

        response.headers.add('Cache-Control', 'max-age=0')
        return response
980876
def make_response(status, headers, payload, environ):
    
    headers_dict = {}
    content_type = None
    for h in headers:
        if h[0].lower() == 'content-type':
            content_type = h[1]
        else:
            headers_dict[h[0]] = h[1]
    return HTTPResponse(body_bytes=payload, content_type=content_type,
                        status=int(status.split()[0]), headers=headers_dict)
498044
def view_on_site(self, request, content_type_id, object_id):
        
        # Look up the object, making sure it's got a get_absolute_url() function.
        try:
            content_type = ContentType.objects.get(pk=content_type_id)
            if not content_type.model_class():
                raise Http404(_("Content type %(ct_id)s object has no associated model") % {
                    'ct_id': content_type_id,
                })
            obj = content_type.get_object_for_this_type(pk=object_id)
        except (ObjectDoesNotExist, ValueError):
            raise Http404(_("Content type %(ct_id)s object %(obj_id)s doesn't exist") % {
                'ct_id': content_type_id,
                'obj_id': object_id,
            })

        try:
            get_absolute_url = obj.get_absolute_url
        except AttributeError:
            raise Http404(_("%(ct_name)s objects don't have a get_absolute_url() method") % {
                'ct_name': content_type.name,
            })
        absurl = get_absolute_url()

        return HttpResponseRedirect(absurl)
1181143
def response(self, status, content_type, content, headers=None):
        

        assert not isinstance(content, (str, bytes)), 'response content cannot be of type str or bytes'
        response_headers = [('Content-Type', content_type)]
        if headers:
            response_headers.extend(headers)
        self.start_response(status, response_headers)
        return content
988518
def render_to_json_response(self, context, **response_kwargs):
        
        return HttpResponse(
            self.convert_context_to_json(context),
            content_type='application/json',
            **response_kwargs
        )
707912
def json_response(data, status=200, serializer=None):
    
    return HttpResponse(json.dumps(data, default=serializer),
                        status=status,
                        content_type='application/json; charset=UTF-8')
883267
def respond_static(self, environ):
        
        path = os.path.normpath(environ["PATH_INFO"])
        if path == "/":
            content = self.index()
            content_type = "text/html"
        else:
            path = os.path.join(os.path.dirname(__file__), path.lstrip("/"))
            try:
                with open(path, "r") as f:
                    content = f.read()
            except IOError:
                return 404
            content_type = guess_type(path)[0]
        return (200, [("Content-Type", content_type)], content)
839210
def RenderHttpResponse(request):
  """"""

  start_time = time.time()
  response = HTTP_REQUEST_HANDLER.HandleRequest(request)
  total_time = time.time() - start_time

  method_name = response.headers.get("X-API-Method", "unknown")
  if response.status_code == 200:
    status = "SUCCESS"
  elif response.status_code == 403:
    status = "FORBIDDEN"
  elif response.status_code == 404:
    status = "NOT_FOUND"
  elif response.status_code == 501:
    status = "NOT_IMPLEMENTED"
  else:
    status = "SERVER_ERROR"

  if request.method == "HEAD":
    metric_name = "api_access_probe_latency"
  else:
    metric_name = "api_method_latency"

  stats_collector_instance.Get().RecordEvent(
      metric_name, total_time, fields=(method_name, "http", status))

  return response
1256727
def _collection_html_response(resources, start=0, stop=20):
    
    return make_response(render_template(
        'collection.html',
        resources=resources[start:stop]))
533531
def features(self):
        
        self._validate_loaded()

        resource = self.FEATURES.format(id=self.id)
        response = Request(self.client, 'get', resource).perform()

        return response.body['data']