planety/prologue

Getting client IP information (like in Jester)

yaroslav-gwit opened this issue · 1 comments

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.

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