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

Getting client IP information (like in Jester) #217

Open
yaroslav-gwit opened this issue Apr 14, 2023 · 1 comment
Open

Getting client IP information (like in Jester) #217

yaroslav-gwit opened this issue Apr 14, 2023 · 1 comment

Comments

@yaroslav-gwit
Copy link

First of all, thank you creating and maintaining this project, it's one of the easiest to use and well documented Nim projects out there.

Now onto the question.
The request object in Jester has the IP flag (it's a trimmed version of the code block):

Request* = ref object
  port*: int
  host*: string
  appName*: string              ## This is set by the user in ``run``, it is
  ip*: string                   ## IP address of the requesting client.

so we can simply do request.ip and get the client IP address.

But Prologue relies on the proxy header flag to get the client IP address (at least as far as I can understand):

Uri* = object
  scheme*, username*, password*: string
  hostname*, port*, path*, query*, anchor*: string
  opaque*: bool
  isIpv6: bool # not expose it for compatibility.

func hostName*(request: Request): string {.inline.} =
  ## Gets the hostname of the request.
  if request.headers.hasKey("REMOTE_ADDR"):
    result = request.headers["REMOTE_ADDR", 0]
  if request.headers.hasKey("x-forwarded-for"):
    result = request.headers["x-forwarded-for", 0]

Would it still be possible to get the remote address like in Jester? I understand that in production Prologue App would be placed behind some kind of a reverse proxy, but still, getting the IP information on the protocol level is very convenient in the development/testing stages.

Thanks in advance.

@arkanoid87
Copy link

I stepped on this issue too and I'm very surprised that this problem exists

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

No branches or pull requests

2 participants