Read and decodes JSON response.
(self, *, encoding=None, loads=json.loads)
| 743 | |
| 744 | @asyncio.coroutine |
| 745 | def json(self, *, encoding=None, loads=json.loads): |
| 746 | """Read and decodes JSON response.""" |
| 747 | if self._content is None: |
| 748 | yield from self.read() |
| 749 | |
| 750 | ctype = self.headers.get(hdrs.CONTENT_TYPE, '').lower() |
| 751 | if 'json' not in ctype: |
| 752 | client_logger.warning( |
| 753 | 'Attempt to decode JSON with unexpected mimetype: %s', ctype) |
| 754 | |
| 755 | stripped = self._content.strip() |
| 756 | if not stripped: |
| 757 | return None |
| 758 | |
| 759 | if encoding is None: |
| 760 | encoding = self._get_encoding() |
| 761 | |
| 762 | return loads(stripped.decode(encoding)) |
| 763 | |
| 764 | if PY_35: |
| 765 | @asyncio.coroutine |
no test coverage detected