edicl / drakma

HTTP client written in Common Lisp
http://edicl.github.io/drakma/
249 stars 59 forks source link

Feature request: API to get the local and remote hosts and port. #115

Open informatimago opened 3 years ago

informatimago commented 3 years ago

When http-request is called with :want-stream t (or even when nil), it would be nice to have a public API to retrieve the local and remove address and port of the TCP connection.

Currently, we have wrapped streams over the native connection stream, which should be considered drakma implementation details, (and I assume could vary depending on the options, chunked/not chunked, ssl, proxy?), and the connection stream is CL implementation specific (assuming usocket is not used, I've not looked, drakma implementaiton detail). So it would be quite inconvenient to access those elements.

This issue is linked to https://github.com/edicl/drakma/issues/116

I would suggest to add two opaque objects in the result values of http-request one for the socket information, and one (optional) for the security information, with the reader API to query them.

An alternative could be to provide the API directly on the stream returned, but this may be inconvenient in case the socket is closed (we'd still want to remember the addresses and port used), or because of the various implementations and wrapper streams on those sockets.

So instead, I'm suggesting an opaque object that could be filled by http-request before losing forgetting the reference to the usocket:socket, with readers similar to the usocket API on it:

(GET-LOCAL-ADDRESS stream-info) -> (or string (vector (unsigned-byte 8)))
(GET-LOCAL-PORT stream-info)    -> (unsigned-byte 16)
(GET-PEER-ADDRESS stream-info)  -> (or string (vector (unsigned-byte 8)))
(GET-PEER-PORT stream-info)     -> (unsigned-byte 16)

optionally, drakma could also provide (which return the list of address and port):

(GET-LOCAL-NAME stream-info)    -> string
(GET-PEER-NAME stream-info)     -> string