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

Get socket parameters in Client or Server #1402

Closed
njaard opened this issue Dec 22, 2017 · 5 comments
Closed

Get socket parameters in Client or Server #1402

njaard opened this issue Dec 22, 2017 · 5 comments
Labels
A-client Area: client. A-server Area: server. B-rfc Blocked: More comments would be useful in determine next steps. C-feature Category: feature. This is adding a new feature.

Comments

@njaard
Copy link

njaard commented Dec 22, 2017

When a Client makes a request, it may connect to one of many hosts associated with the URL.

I would like to have a way to access the IP address associated with the remote host. This is accessible from tokio via NetSocket::peer_addr().

Logically, one should also be able to access the local address with local_addr(), and so it makes sense to support access to many of the apis made available on the socket-level from tokio.

@njaard njaard changed the title Get socket parameters from request Get socket parameters from Client Dec 22, 2017
@seanmonstar
Copy link
Member

I agree there are cases where this is desirable, but there are also reasons it doesn't exist yet. These are properties specific to TCP, whereas hyper (and HTTP even) don't require the underlying transport to be TCP (Unix domain sockets don't have a concept of addresses, for example).

It'd probably need some sort of middleware between when a transport is chosen ready to use and when a Response is given back to the user, but there isn't currently anything to really do that. For now, you'd probably need a custom Connect implementation that stores the relevant socket information in something that you can check outside of hyper.

@seanmonstar seanmonstar added A-client Area: client. E-hard Effort: hard. Likely requires a deeper understanding of how hyper's internals work. C-feature Category: feature. This is adding a new feature. labels Dec 26, 2017
@seanmonstar
Copy link
Member

seanmonstar commented Mar 14, 2018

When would one expect to be able to receive this information? You generally give a Request to the Client, and don't know what connection it will use at that point. If it's fine that this information is received on the Response, we could optionally put this information in the Response::extensions.

If we went that way, I'd think that instead of exposing exactly that the type is in extensions, some sort of ConnectionInfo type could exist that can be get and set on the Response (and similar info could be useful on the incoming server Request).

A possible API:

pub struct ConnectionInfo {
    local_addr: Option<SocketAddr>,
    remote_addr: Option<SocketAddr>,
    // maybe new fields in the future
}

impl ConnectionInfo {
    pub fn get(res: &Response) -> ConnectionInfo {
        // fetch an internal type from `extensions()`,
        // fill in whatever info was possible
    }
    
    pub fn set(&self, res: &mut Response) {
        
    }
}

@njaard
Copy link
Author

njaard commented Mar 16, 2018

Sometimes you want to write logs and include the remote host in the log.

@seanmonstar
Copy link
Member

Yes, of course. I was asking at what point would it be expected to access the remote info? Is it fine as a property of the response?

@seanmonstar seanmonstar added B-rfc Blocked: More comments would be useful in determine next steps. and removed E-hard Effort: hard. Likely requires a deeper understanding of how hyper's internals work. labels Jun 8, 2018
@njaard
Copy link
Author

njaard commented Jun 8, 2018

I guess you could also want it even earlier than that: you establish a TCP connection, log the remote host and then SSL auth fails.

@seanmonstar seanmonstar changed the title Get socket parameters from Client Get socket parameters in Client or Server Jun 28, 2018
@seanmonstar seanmonstar added the A-server Area: server. label Jun 28, 2018
seanmonstar added a commit that referenced this issue Jul 4, 2018
- Adds `client::Builder::set_conn_info` to opt-in to having connection
  info added to `Response`s from clients.
- Adds `ext::ConnectionInfo` that allows querying types (like a
  `Response`) for connection info.

Closes #1402
seanmonstar added a commit that referenced this issue Jul 5, 2018
- Adds `client::connect::Connected::extra()`, which allows connectors to
  specify arbitrary custom information about a connected transport.

If a connector provides this extra value, it will be set in the
`Response` extensions.

Closes #1402
seanmonstar added a commit that referenced this issue Jul 5, 2018
- Adds `client::connect::Connected::extra()`, which allows connectors to
  specify arbitrary custom information about a connected transport.

If a connector provides this extra value, it will be set in the
`Response` extensions.

Closes #1402
seanmonstar added a commit that referenced this issue Jul 5, 2018
- Adds `client::connect::Connected::extra()`, which allows connectors to
  specify arbitrary custom information about a connected transport.

If a connector provides this extra value, it will be set in the
`Response` extensions.

Closes #1402
seanmonstar added a commit that referenced this issue Oct 16, 2018
- Adds `client::connect::Connected::extra()`, which allows connectors to
  specify arbitrary custom information about a connected transport.

If a connector provides this extra value, it will be set in the
`Response` extensions.

Closes #1402
seanmonstar added a commit that referenced this issue Oct 16, 2018
- Adds `client::connect::Connected::extra()`, which allows connectors to
  specify arbitrary custom information about a connected transport.

If a connector provides this extra value, it will be set in the
`Response` extensions.

Closes #1402
seanmonstar added a commit that referenced this issue Oct 16, 2018
- Adds `client::connect::Connected::extra()`, which allows connectors to
  specify arbitrary custom information about a connected transport.

If a connector provides this extra value, it will be set in the
`Response` extensions.

Closes #1402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-client Area: client. A-server Area: server. B-rfc Blocked: More comments would be useful in determine next steps. C-feature Category: feature. This is adding a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants