Skip to content
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

fix: trust proxy REMOTE_ADDR not working in Swoole #52889

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

chuoke
Copy link
Contributor

@chuoke chuoke commented Sep 23, 2024

When using REMOTE_ADDR set the trust proxy in Swoole, like this:

      $middleware->trustProxies(
            at: [
                'REMOTE_ADDR',
            ],
            headers: Request::HEADER_X_FORWARDED_FOR
        );

Is nothing set to request->trustedProxies because $_SERVER['REMOTE_ADDR'] does not exist in Swoole. But Laravel internally converts the server information in Swoole into the request->server attribute, which includes REMOTE_ADDR, and then request()->server->get('REMOTE_ADDR') can get the corresponding value normally.

This leads to some logical ambiguity and increases the cognitive burden and learning cost.

So we need to unify the logic to avoid inconsistency. I can't change this in the Request class because of the method attribute restrictions, so the solution I've come up with so far is this, it works for me, and I hope there's another better way to solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant