Skip to content

Overriding HttpServer::MAXIMUM_BUFFER_SIZE #436

Description

@ozahorulia

Hello. I just upgraded from 0.8.7 to 1.5.0. Before the upgrade, we could accept requests up to 10MB. But now all the requests are always being cut. The problem is that LimitConcurrentRequestsMiddleware used to operate INI's post_max_size settings, and now it's limited by HttpServer::getMaxRequestSize(), and its result can not be higher than HttpServer::MAXIMUM_BUFFER_SIZE. Is there any workaround to accept heavy packages?

RequestBodyBufferMiddleware has a solution for this (it ignores sizeLimit if an actual size is higher):

        // request body of known size exceeding limit
        $sizeLimit = $this->sizeLimit;
        if ($size > $this->sizeLimit) {
            $sizeLimit = 0;
        }

But LimitConcurrentRequestsMiddleware is always being limited to MAXIMUM_BUFFER_SIZE.

I find the logic pretty unclear, because RequestBodyBufferMiddleware does accept packages higher than MAXIMUM_BUFFER_SIZE, but at the same time it's always limited due to LimitConcurrentRequestsMiddleware.

Activity

  1. ozahorulia commented on Jan 11, 2022

    @ozahorulia
    Author

    Fixed by explicitly passing middleware objects to HttpServer:

            $requestMaxSize = $this->iniSizeToBytes($this->requestMaxSize);
            $memoryLimit = $this->iniSizeToBytes($this->memoryLimit);
    
            $requestHandlers = [];
            $requestHandlers[] = new StreamingRequestMiddleware();
    
            $concurrency = $this->getConcurrentRequestsLimit($memoryLimit, $requestMaxSize);
            if ($concurrency !== null) {
                $requestHandlers[] = new LimitConcurrentRequestsMiddleware($concurrency);
            }
    
            $requestHandlers[] = new RequestBodyBufferMiddleware($requestMaxSize);
            if ($this->enablePostDataReading) {
                $requestHandlers[] = new RequestBodyParserMiddleware();
            }
    
            $requestHandlers[] = $callback;
    
            return new React\Http\HttpServer(...$requestHandlers);
    
  2. SimonFrings commented on Jan 31, 2022

    @SimonFrings
    Member

    Hey @hast, thanks for opening this up 👍

    It seems like you already found your way of dealing with this, a similar approach can be found inside the documentation. You can also take a look at #371.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions