Skip to content

Commit ba295cf

Browse files
committed
BREAKING Returns HTTP code 413 when post_max_size is exceeded #11708
This case is not directly reported by PHP itself, neither via `UploadedFileInterface`, so we try our best to detect the situation and immediately returns the HTTP code 413. We do it immediately because when the case happens, PHP will leave $_POST entirely empty so we have no way to do anything further. So we let the client know via HTTP status and it is up to him to handle in the best way possible. When a 413 happens, the response body contains a detailed message similar to: ```json {"message": "The server `post_max_size` is configured to accept 10.00 MiB, but received 28.00 MiB"} ``` It is also BREAKING because `UploadMiddleware::processRequest()` is dropped entirely without replacement. If you need to use this library but you don't already use PSR-15 middleware, then you will have to implement a workaround yourself.
1 parent 7bd7177 commit ba295cf

File tree

6 files changed

+295
-251
lines changed

6 files changed

+295
-251
lines changed

README.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,6 @@ to your framework documentation.
4545

4646
If your framework does not support PSR-15 middleware, you will probably
4747
need some kind of bridge. Again, refer to your framework for specific instructions.
48-
Or else, you could use the direct usage below for manual integration.
49-
50-
### Direct usage
51-
52-
If you don't use middleware, it can be called directly like so:
53-
54-
```php
55-
<?php
56-
57-
use GraphQL\Server\StandardServer;
58-
use GraphQL\Upload\UploadMiddleware;
59-
use Laminas\Diactoros\ServerRequestFactory;
60-
61-
// Create request (or get it from a framework)
62-
$request = ServerRequestFactory::fromGlobals();
63-
$request = $request->withParsedBody(json_decode($request->getBody()->getContents(), true));
64-
65-
// Process uploaded files
66-
$uploadMiddleware = new UploadMiddleware();
67-
$request = $uploadMiddleware->processRequest($request);
68-
69-
// Execute request and emits response
70-
$server = new StandardServer(/* your config here */);
71-
$result = $server->executePsrRequest($request);
72-
$server->getHelper()->sendResponse($result);
73-
```
7448

7549
### Usage in schema
7650

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
}
2525
},
2626
"require": {
27-
"php": "^8.1",
27+
"php": "^8.2",
2828
"ext-json": "*",
2929
"psr/http-server-middleware": "^1.0",
30-
"webonyx/graphql-php": "^15.0"
30+
"webonyx/graphql-php": "^15.0",
31+
"laminas/laminas-diactoros": "^3.6"
3132
},
3233
"license": "MIT",
3334
"require-dev": {
3435
"friendsofphp/php-cs-fixer": "@stable",
35-
"laminas/laminas-diactoros": "@stable",
3636
"phpstan/phpstan": "@stable",
3737
"phpunit/phpunit": "@stable"
3838
}

0 commit comments

Comments
 (0)