| 1720 | |
| 1721 | @DictProperty('environ', 'bottle.request.body', read_only=True) |
| 1722 | def _body(self): |
| 1723 | mp_markup = None |
| 1724 | mp_boundary_match = MULTIPART_BOUNDARY_PATT.match(self.environ.get('CONTENT_TYPE', '')) |
| 1725 | if mp_boundary_match is not None: |
| 1726 | mp_markup = MPBodyMarkup(tob(mp_boundary_match.group(1))) |
| 1727 | try: |
| 1728 | read_func = self.environ['wsgi.input'].read |
| 1729 | except KeyError: |
| 1730 | self.environ['wsgi.input'] = BytesIO() |
| 1731 | return self.environ['wsgi.input'] |
| 1732 | body_iter = self._iter_chunked if self.chunked else self._iter_body |
| 1733 | body, body_size, is_temp_file = BytesIO(), 0, False |
| 1734 | for part in body_iter(read_func, self.MEMFILE_MAX): |
| 1735 | body.write(part) |
| 1736 | if mp_markup is not None: |
| 1737 | mp_markup.parse(part) |
| 1738 | body_size += len(part) |
| 1739 | if not is_temp_file and body_size > self.MEMFILE_MAX: |
| 1740 | body, tmp = NamedTemporaryFile(mode='w+b'), body |
| 1741 | body.write(tmp.getvalue()) |
| 1742 | del tmp |
| 1743 | is_temp_file = True |
| 1744 | body.multipart_markup = mp_markup |
| 1745 | self.environ['wsgi.input'] = body |
| 1746 | body.seek(0) |
| 1747 | return body |
| 1748 | |
| 1749 | def _get_body_string(self, maxread): |
| 1750 | """ Read body into a string. Raise HTTPError(413) on requests that are |