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

expose the last_forwarded_ip/2 function for usage outside of Plug #9

Closed

Conversation

Gazler
Copy link

@Gazler Gazler commented Jan 14, 2019

In some circumstances, it is possible to get a subset of headers without the
full conn. An example of this is in Phoenix sockets, where only x_headers can be
fetched.

https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#socket/3-shared-configuration

In this case, currently using RemoteIP involves doing something like this as
conn is not available:

def connect({connect_info: %{x_headers: headers}}) do
  RemoteIp.call(%Plug.Conn{req_headers: headers}, RemoteIp.init()).remote_ip
end

With this PR, someone using this library with Phoenix sockets could do:

  RemoteIp.last_forwarded_ip(headers)

In some circumstances, it is possible to get a subset of headers without the
full conn. An example of this is in Phoenix sockets, where only x_headers can be
fetched.

https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#socket/3-shared-configuration

In this case, currently using RemoteIP involves doing something like this as
conn is not available:

```elixir
def connect({connect_info: %{x_headers: headers}}) do
  RemoteIp.call(%Plug.Conn{req_headers: headers}, RemoteIp.init()).remote_ip
end
```

With this PR, someone using this library with Phoenix sockets could do:

```elixir
  RemoteIp.last_forwarded_ip(headers)
```
@ajvondrak
Copy link
Owner

Sorry for the delayed response. It's a great idea, and I appreciate the PR. I'll probably want to massage around the actual implementation, both to appease my delicate sensibilities (I get weird about things 😅) and in light of possibly-changing APIs from #8. I'll try to get to this soon. 👍

@ajvondrak ajvondrak closed this in e42a8cc Oct 21, 2019
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.

2 participants