예제 #1
0
 async def handle_request(self, request):
     # Check for body size overflow.
     if request.content_length is not None and request.content_length > self._max_request_body_size:
         raise HTTPRequestEntityTooLarge()
     # Buffer the body.
     content_length = 0
     with SpooledTemporaryFile(max_size=self._inbuf_overflow) as body:
         while True:
             block = await request.content.readany()
             if not block:
                 break
             content_length += len(block)
             if content_length > self._max_request_body_size:
                 raise HTTPRequestEntityTooLarge()
             body.write(block)
         body.seek(0)
         # Get the environ.
         environ = self._get_environ(request, body, content_length)
         status, reason, headers, body = await self._loop.run_in_executor(
             self._executor,
             _run_application,
             self._application,
             environ,
         )
     # All done!
     return Response(
         status=status,
         reason=reason,
         headers=headers,
         body=body,
     )
예제 #2
0
 def handle_request(self, request):
     # Check for body size overflow.
     if (request.content_length is not None
             and request.content_length > self._max_request_body_size):
         raise HTTPRequestEntityTooLarge()
     # Buffer the body.
     content_length = 0
     with SpooledTemporaryFile(max_size=self._inbuf_overflow) as body:
         while True:
             block = yield from request.content.readany()
             if not block:
                 break
             content_length += len(block)
             if content_length > self._max_request_body_size:
                 raise HTTPRequestEntityTooLarge()
             body.write(block)
         body.seek(0)
         # Get the environ.
         environ = self._get_environ(request, body, content_length)
         environ['async.writer'] = request.writer
         environ['async.protocol'] = request.protocol
         status, reason, headers, body = yield from spawn_greenlet(
             _run_application,
             self._application,
             environ,
         )
         # All done!
         return Response(
             status=status,
             reason=reason,
             headers=headers,
             body=body,
         )
예제 #3
0
    def handle_request(self, request):
        # Check for body size overflow.
        if request.content_length is not None and request.content_length > self._max_request_body_size:
            raise HTTPRequestEntityTooLarge()
        # Buffer the body.
        body_buffer = ReadBuffer(self._inbuf_overflow,
                                 self._max_request_body_size, self._loop,
                                 self._executor)

        try:
            while True:
                block = yield from request.content.readany()
                if not block:
                    break
                yield from body_buffer.write(block)
            # Seek the body.
            body, content_length = yield from body_buffer.get_body()
            # Get the environ.
            environ = self._get_environ(request, body, content_length)
            status, reason, headers, body = yield from self._loop.run_in_executor(
                self._executor,
                _run_application,
                self._application,
                environ,
            )
            # All done!
            return Response(
                status=status,
                reason=reason,
                headers=headers,
                body=body,
            )

        finally:
            yield from body_buffer.close()
예제 #4
0
 async def write(self, data):
     self._content_length += len(data)
     # Check for body size overflow. The request might be streaming, so we check with every chunk.
     if self._content_length > self._max_request_body_size:
         raise HTTPRequestEntityTooLarge()
     # Overflow onto disk, if required.
     if not self._overflow and self._content_length > self._inbuf_overflow:
         self._overflow = True
         overflow_body = await self._run(TemporaryFile)
         await self._run(overflow_body.write, self._body.getbuffer())
         self._body.close()
         self._body = overflow_body
     # Write the block.
     await self._run(self._body.write, data)