Skip to content

Add support for passing socket info through to SERVER superglobal #10

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

Merged
merged 1 commit into from
May 21, 2025

Conversation

Qard
Copy link
Member

@Qard Qard commented May 21, 2025

I've added optional support for passing through local and remote socket information to the $_SERVER superglobal.

const request = new Request({
  url: 'http://example.com/index.php',
  socket: {
    localAddress: '127.0.0.1',
    localPort: 1234,
    remoteAddress: '123.123.123.123',
    remotePort: 54321
  }
})

Note that this is also designed to line up with the names on req.socket so you can pass that in as the socket info object too.

I've also improved the safety of the Request and Response constructors a bit, making it throw proper JS errors rather than using unwrap() or expect() which would kill the process on invalid inputs.

Also, argv is now required as it always should have been. 😅

@Qard Qard added the enhancement New feature or request label May 21, 2025
@mcollina
Copy link
Member

Why is this needed?

@Qard Qard force-pushed the add-socket-data-to-server-superglobal branch from 3358cf5 to 32c2501 Compare May 21, 2025 10:20
@Qard
Copy link
Member Author

Qard commented May 21, 2025

The main thing here is just fixing the HTTP_HOST issue you had--it will pull it from the headers properly now that the extra line is removed. But this also does some safety cleanup and ensures the rest of the socket info is set correctly.

These variables are probably not super important, but they are part of the CGI spec and should be present. I assume any IP-ban plugins would read from those, so we should probably have them.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link

@ShogunPanda ShogunPanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non blocking nit, LGTM!

@Qard Qard force-pushed the add-socket-data-to-server-superglobal branch from 32c2501 to 6602552 Compare May 21, 2025 10:44
@Qard Qard merged commit b663663 into main May 21, 2025
11 checks passed
@Qard Qard deleted the add-socket-data-to-server-superglobal branch May 21, 2025 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants