async def resolve(self, receive: ASGIReceive, headers: http.Headers, content_type: http.Header) -> FileStream: try: negotiate_content_type([self], content_type) except exceptions.NoCodecAvailable: raise exceptions.UnsupportedMediaType() return await self.decode(receive, headers)
def resolve(self, content: http.Body, headers: http.Headers): if not content: return None content_type = headers.get('Content-Type') try: codec = negotiate_content_type(self.codecs, content_type) except exceptions.NoCodecAvailable: raise exceptions.UnsupportedMediaType() try: return codec.decode(content, headers=headers) except exceptions.ParseError as exc: raise exceptions.BadRequest(str(exc))
def resolve(self, content: Body, headers: Headers, parameter: Parameter): if not content: raise NotImplementedError content_type = headers.get('Content-Type') try: codec = negotiate_content_type(self.codecs, content_type) except exceptions.NoCodecAvailable: raise exceptions.UnsupportedMediaType() try: value = codec.decode(content, headers=headers) except exceptions.ParseError as exc: raise exceptions.BadRequest(str(exc)) try: return self.handle_parameter(parameter, value) except Exception: raise exceptions.BadRequest(f"{parameter.name} invalid")
def decode_response_content(self, response): """ Given an HTTP response, return the decoded data. """ if not response.content: return None content_type = response.headers.get("content-type") codec = conneg.negotiate_content_type(self.decoders, content_type) options = {"base_url": response.url} if "content-type" in response.headers: options["content_type"] = response.headers["content-type"] if "content-disposition" in response.headers: options["content_disposition"] = response.headers[ "content-disposition"] return codec.decode(response.content, **options)
def decode_response_content(self, response): """ Given an HTTP response, return the decoded data. """ if not response.content: return None content_type = response.headers.get('content-type') codec = conneg.negotiate_content_type(self.decoders, content_type) options = {'base_url': response.url} if 'content-type' in response.headers: options['content_type'] = response.headers['content-type'] if 'content-disposition' in response.headers: options['content_disposition'] = response.headers[ 'content-disposition'] return codec.decode(response.content, **options)