-
Notifications
You must be signed in to change notification settings - Fork 597
Implement a more comprehensive way to get connection information #1269
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
Conversation
Hrm. Looking into the work required to implement this in Cowboy, it's not insignificant. Cowboy easily provides all of the existing info in peer_data, but basically nothing else (I suspect that this is probably why the existing Plug.Conn.Adapter contract looks the way it does). It'd be a whole set of kinda subtle PRs all the way up to Ranch to get this information sourced, for what amounts to a pretty niche use case. Not entirely sure this is a good use of effort, TBH. WDYT? |
Out of curiosity here... It is not possible to do an adapter check, return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just two tiny comments.
I think the better option here might be to make |
We could also make the other keys in |
d02c753
to
9d2a226
Compare
Trying a different tack here with separate |
lib/plug/conn.ex
Outdated
raise "get_sock_data not supported by #{inspect(adapter)}." <> | ||
"You should either delete the call to `get_sock_data/1` or switch to an " <> | ||
"adapter that does support this call such as Bandit." | ||
end | ||
end | ||
|
||
@doc """ | ||
Returns SSL data for the connection if present. If the connection is not SSL, returns nil | ||
""" | ||
@spec get_ssl_data(t) :: Plug.Conn.Adapter.ssl_data() | ||
def get_ssl_data(%Conn{adapter: {adapter, payload}}) do | ||
if function_exported?(adapter, :get_ssl_data, 1) do | ||
adapter.get_ssl_data(payload) | ||
else | ||
raise "get_ssl_data not supported by #{inspect(adapter)}." <> | ||
"You should either delete the call to `get_ssl_data/1` or switch to an " <> | ||
"adapter that does support this call such as Bandit." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly to keep ti adapter agnostic :)
raise "get_sock_data not supported by #{inspect(adapter)}." <> | |
"You should either delete the call to `get_sock_data/1` or switch to an " <> | |
"adapter that does support this call such as Bandit." | |
end | |
end | |
@doc """ | |
Returns SSL data for the connection if present. If the connection is not SSL, returns nil | |
""" | |
@spec get_ssl_data(t) :: Plug.Conn.Adapter.ssl_data() | |
def get_ssl_data(%Conn{adapter: {adapter, payload}}) do | |
if function_exported?(adapter, :get_ssl_data, 1) do | |
adapter.get_ssl_data(payload) | |
else | |
raise "get_ssl_data not supported by #{inspect(adapter)}." <> | |
"You should either delete the call to `get_ssl_data/1` or switch to an " <> | |
"adapter that does support this call such as Bandit." | |
raise "get_sock_data not supported by #{inspect(adapter)}" | |
end | |
end | |
@doc """ | |
Returns SSL data for the connection if present. If the connection is not SSL, returns nil | |
""" | |
@spec get_ssl_data(t) :: Plug.Conn.Adapter.ssl_data() | |
def get_ssl_data(%Conn{adapter: {adapter, payload}}) do | |
if function_exported?(adapter, :get_ssl_data, 1) do | |
adapter.get_ssl_data(payload) | |
else | |
raise "get_ssl_data not supported by #{inspect(adapter)}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nits and we can ship this!!!
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
Ready for review - since the new callbacks are optional this can go out anytime and underlying support can come out on its own schedule (I'll be getting Bandit's support done in the next few days, bad weather permitting) |
💚 💙 💜 💛 ❤️ |
Aw shoot sorry I missed those changes - GitHub stacked all of your suggestions such that I had to do them manually. |
No worries!
|
Scope of changes:
c:Plug.Conn.Adapter.get_sock_data/1
andc:Plug.Conn.Adapter.get_ssl_data/1
callbacksPlug.Conn.get_sock_data/1
andPlug.Conn.get_ssl_data/1