-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: add setup check for request buffering on FPM #54912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
susnux
wants to merge
1
commit into
master
Choose a base branch
from
fix/setup-check-buffering
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Settings\SetupChecks; | ||
|
|
||
| use GuzzleHttp\Psr7; | ||
| use OCP\Http\Client\IClientService; | ||
| use OCP\IConfig; | ||
| use OCP\IL10N; | ||
| use OCP\IURLGenerator; | ||
| use OCP\SetupCheck\CheckServerResponseTrait; | ||
| use OCP\SetupCheck\ISetupCheck; | ||
| use OCP\SetupCheck\SetupResult; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| class RequestBuffering implements ISetupCheck { | ||
|
|
||
| use CheckServerResponseTrait; | ||
|
|
||
| public function __construct( | ||
| protected IL10N $l10n, | ||
| protected IConfig $config, | ||
| protected IURLGenerator $urlGenerator, | ||
| protected IClientService $clientService, | ||
| protected LoggerInterface $logger, | ||
| ) { | ||
| } | ||
|
|
||
| public function getCategory(): string { | ||
| return 'network'; | ||
| } | ||
|
|
||
| public function getName(): string { | ||
| return $this->l10n->t('Request buffering'); | ||
| } | ||
|
|
||
| public function run(): SetupResult { | ||
| $usingFPM = function_exists('fastcgi_finish_request'); | ||
| if (!$usingFPM && !\OC::$CLI) { | ||
| return SetupResult::success( | ||
| $this->l10n->t('Not using PHP-FPM.') | ||
| ); | ||
| } | ||
|
|
||
| $works = null; | ||
| $stream = Psr7\Utils::streamFor(str_repeat('x', 1337)); | ||
| $options = [ | ||
| 'body' => $stream, | ||
| 'headers' => [ | ||
| 'Transfer-Encoding' => 'chunked', | ||
| ], | ||
| ]; | ||
| $url = $this->urlGenerator->linkToRoute('settings.CheckSetup.checkContentLengthHeader'); | ||
| foreach ($this->runRequest('PUT', $url, ['ignoreSSL' => true, 'options' => $options]) as $response) { | ||
| $contentType = $response->getHeader('Content-Type'); | ||
| if (!str_contains(strtolower($contentType), 'application/json')) { | ||
| continue; | ||
| } | ||
|
|
||
| $body = $response->getBody(); | ||
| $body = is_resource($body) ? stream_get_contents($body) : $body; | ||
| $works = $works || $body === '"1337"'; | ||
| } | ||
|
|
||
| if ($works === null) { | ||
| return SetupResult::info( | ||
| $this->l10n->t('Could not check that your web server has configured request buffering. Please check manually.'), | ||
| ); | ||
| } elseif ($works === true) { | ||
| return SetupResult::success( | ||
| $this->l10n->t('Your web server seems to have request buffering configured correctly.'), | ||
| ); | ||
| } else { | ||
| if ($usingFPM) { | ||
| return SetupResult::error( | ||
| $this->l10n->t('Your web server is not configured for request buffering, this will cause broken uploads with some clients.') | ||
| . ' ' | ||
| . $this->l10n->t('Due to a limitation of PHP-FPM chunked requests will not be passed to Nextcloud if the server does not buffer such requests.'), | ||
| ); | ||
| } else { | ||
| // Not using FPM but we are on CLI so we do not know if FPM is used | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The endpoint could return $usingFPM while we’re at it, no?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! |
||
| return SetupResult::warning( | ||
| $this->l10n->t('Your web server is not configured for request buffering, if you are running PHP-FPM this will cause broken uploads with some clients.') | ||
| . ' ' | ||
| . $this->l10n->t('Due to a limitation of PHP-FPM chunked requests will not be passed to Nextcloud if the server does not buffer such requests.'), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d like a comment for this one, what does it mean if content type is something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then its not a Nextcloud response - some safe guard for reverse proxys so the following check on the response can be done.