diff options
author | Wolfy-J <[email protected]> | 2020-05-19 15:17:41 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2020-05-19 15:17:41 +0300 |
commit | c3c7165bf4dd5a9929f506c25ccf5d41c7b69c83 (patch) | |
tree | f7b632e8b9c3151e985ef9361077942af9c074b3 | |
parent | 5b6269f1f505bd3ebda676a9e9c90f7b346deb78 (diff) | |
parent | 5600d806fbc0339d629501b45b09f8fc7f64e260 (diff) |
Merge remote-tracking branch 'origin/master'
-rw-r--r-- | .github/ISSUE_TEMPLATE/bug_report.md | 38 | ||||
-rw-r--r-- | .github/ISSUE_TEMPLATE/feature_request.md | 20 | ||||
-rw-r--r-- | .github/workflows/ci-build.yml | 6 | ||||
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | bors.toml | 2 | ||||
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | composer.json | 4 | ||||
-rw-r--r-- | service/http/handler.go | 16 | ||||
-rw-r--r-- | src/HttpClient.php | 2 | ||||
-rw-r--r-- | src/PSR7Client.php | 14 | ||||
-rw-r--r-- | src/Worker.php | 30 |
12 files changed, 121 insertions, 22 deletions
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..448a1aa4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG]" +labels: B-bug, F-need-verification +assignees: 48d90782 + +--- + +--- +name: Bug Report +about: Issue in HTTP module <replace> +labels: A-network <replace> +--- +<!-- +Thank you for filing a bug report! 🐛 Please provide a short summary of the bug, +along with any information you feel relevant to replicating the bug. +--> + +I tried this code: + +```go +<code> +``` + +I expected to see this happen: *explanation* + +Instead, this happened: *explanation* + +The version of RR used: *explanation* + +Errortrace, Backtrace or Panictrace +``` +<backtrace> +``` + +</p> +</details> diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..65ac962a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FEATURE REQUEST]" +labels: C-feature-request +assignees: 48d90782, vvval, wolfy-j + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 6045fd57..57edc624 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - php: [7.3, 7.4] + php: [7.2, 7.3, 7.4] go: [1.13, 1.14] os: [ubuntu-latest] env: @@ -57,8 +57,8 @@ jobs: - name: Install Composer dependencies run: composer install --prefer-dist --no-interaction --no-suggest # --prefer-source - - name: Analyze PHP sources - run: composer analyze +# - name: Analyze PHP sources +# run: composer analyze - name: Install Go dependencies run: go mod download diff --git a/CHANGELOG.md b/CHANGELOG.md index 229609fd..b17ad8da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +v1.8.0 (05.05.2020) +------------------- +- Update goridge version to 2.4.0 +- Update PHP version to the 7.2 (currently minimum supported) +- See the full milestone here: [link](https://github.com/spiral/roadrunner/issues?q=is%3Aclosed+milestone%3A1.8.0) + v1.7.1 (22.04.2020) ------------------- - Syscall usage optimized. Now the data is packing and sending via 1 (or 2 in some cases) send_socket calls, instead of 2-3 (by @vvval) @@ -44,7 +44,8 @@ Features: - Payload context and body - Protocol, worker and job level error management (including PHP errors) - Very fast (~250k rpc calls per second on Ryzen 1700X using 16 threads) -- Integrations with Symfony, Laravel, Slim, CakePHP, Zend Expressive, Spiral +- Integrations with Symfony, Laravel, Slim, CakePHP, Zend Expressive +- Application server for [Spiral](https://github.com/spiral/framework) - Automatic reloading on file changes - Works on Windows (Unix sockets (AF_UNIX) supported on Windows 10) @@ -1,4 +1,6 @@ status = [ +'Build (PHP 7.2, Go 1.13, OS ubuntu-latest)', +'Build (PHP 7.2, Go 1.14, OS ubuntu-latest)', 'Build (PHP 7.3, Go 1.13, OS ubuntu-latest)', 'Build (PHP 7.3, Go 1.14, OS ubuntu-latest)', 'Build (PHP 7.4, Go 1.13, OS ubuntu-latest)', @@ -3,7 +3,7 @@ cd $(dirname "${BASH_SOURCE[0]}") OD="$(pwd)" # Pushes application version into the build information. -RR_VERSION=1.7.1 +RR_VERSION=1.8.0 # Hardcode some values to the core package LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.Version=${RR_VERSION}" diff --git a/composer.json b/composer.json index fde54fa8..c4fa8609 100644 --- a/composer.json +++ b/composer.json @@ -14,10 +14,10 @@ } ], "require": { - "php": "^7.1", + "php": "^7.2", "ext-json": "*", "ext-curl": "*", - "spiral/goridge": "^2.3", + "spiral/goridge": "^2.4", "psr/http-factory": "^1.0", "psr/http-message": "^1.0", "symfony/console": "^2.5.0 || ^3.0.0 || ^4.0.0 || ^5.0.0", diff --git a/service/http/handler.go b/service/http/handler.go index 3c667035..ab7c382b 100644 --- a/service/http/handler.go +++ b/service/http/handler.go @@ -175,7 +175,23 @@ func (h *Handler) resolveIP(r *Request) { return } + // The logic here is the following: + // In general case, we only expect X-Real-Ip header. If it exist, we get the IP addres from header and set request Remote address + // But, if there is no X-Real-Ip header, we also trying to check CloudFlare headers + // True-Client-IP is a general CF header in which copied information from X-Real-Ip in CF. + // CF-Connecting-IP is an Enterprise feature and we check it last in order. + // This operations are near O(1) because Headers struct are the map type -> type MIMEHeader map[string][]string if r.Header.Get("X-Real-Ip") != "" { r.RemoteAddr = fetchIP(r.Header.Get("X-Real-Ip")) + return + } + + if r.Header.Get("True-Client-IP") != "" { + r.RemoteAddr = fetchIP(r.Header.Get("True-Client-IP")) + return + } + + if r.Header.Get("CF-Connecting-IP") != "" { + r.RemoteAddr = fetchIP(r.Header.Get("CF-Connecting-IP")) } } diff --git a/src/HttpClient.php b/src/HttpClient.php index 42c434a8..4ca152c8 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -34,7 +34,7 @@ final class HttpClient * @return mixed[]|null Request information as ['ctx'=>[], 'body'=>string] * or null if termination request or invalid context. */ - public function acceptRequest() + public function acceptRequest(): ?array { $body = $this->getWorker()->receive($ctx); if (empty($body) && empty($ctx)) { diff --git a/src/PSR7Client.php b/src/PSR7Client.php index 98897890..777dd891 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -10,11 +10,11 @@ declare(strict_types=1); namespace Spiral\RoadRunner; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\ServerRequestFactoryInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\UploadedFileFactoryInterface; +use Psr\Http\Message\UploadedFileInterface; /** * Manages PSR-7 request and response. @@ -69,7 +69,7 @@ class PSR7Client /** * @return ServerRequestInterface|null */ - public function acceptRequest() + public function acceptRequest(): ?ServerRequestInterface { $rawRequest = $this->httpClient->acceptRequest(); if ($rawRequest === null) { @@ -101,11 +101,11 @@ class PSR7Client } if ($rawRequest['ctx']['parsed']) { - $request = $request->withParsedBody(json_decode($rawRequest['body'], true)); - } else { - if ($rawRequest['body'] !== null) { - $request = $request->withBody($this->streamFactory->createStream($rawRequest['body'])); - } + return $request->withParsedBody(json_decode($rawRequest['body'], true)); + } + + if ($rawRequest['body'] !== null) { + return $request->withBody($this->streamFactory->createStream($rawRequest['body'])); } return $request; diff --git a/src/Worker.php b/src/Worker.php index d9de0fa9..2da16e86 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -11,6 +11,8 @@ namespace Spiral\RoadRunner; use Spiral\Goridge\Exceptions\GoridgeException; use Spiral\Goridge\RelayInterface as Relay; +use Spiral\Goridge\SocketRelay; +use Spiral\Goridge\StreamRelay; use Spiral\RoadRunner\Exception\RoadRunnerException; /** @@ -28,15 +30,19 @@ class Worker // Send as response context to request worker termination public const STOP = '{"stop":true}'; - /** @var Relay */ + /** @var Relay|StreamRelay|SocketRelay */ private $relay; + /** @var bool */ + private $optimizedRelay; + /** * @param Relay $relay */ public function __construct(Relay $relay) { $this->relay = $relay; + $this->optimizedRelay = method_exists($relay, 'sendPackage'); } /** @@ -83,12 +89,22 @@ class Worker */ public function send(string $payload = null, string $header = null): void { - $this->relay->sendPackage( - (string)$header, - Relay::PAYLOAD_CONTROL | ($header === null ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW), - (string)$payload, - Relay::PAYLOAD_RAW - ); + if (!$this->optimizedRelay) { + if ($header === null) { + $this->relay->send('', Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE); + } else { + $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW); + } + + $this->relay->send((string)$payload, Relay::PAYLOAD_RAW); + } else { + $this->relay->sendPackage( + (string)$header, + Relay::PAYLOAD_CONTROL | ($header === null ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW), + (string)$payload, + Relay::PAYLOAD_RAW + ); + } } /** |