-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Thank you for this library, it looks almost exactly like what I need.
In
httpx-secure/httpx_secure/__init__.py
Lines 125 to 137 in 57ca973
| async def _resolve(self, request: Request, hostname: str, port: int) -> str: | |
| try: | |
| with fail_after(self.connect_timeout): | |
| async with await connect_tcp( | |
| hostname, | |
| port, | |
| happy_eyeballs_delay=self.happy_eyeballs_delay, | |
| ) as stream: | |
| return stream._raw_socket.getpeername()[0] | |
| except TimeoutError as e: | |
| raise ConnectTimeout(str(e), request=request) from e | |
| except OSError as e: | |
| raise ConnectError(str(e), request=request) from e |
you open a TCP connection to the host just to get the IP. Why not do something like
socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
to get the IP?
The drawback I see with the connection is that you have to establish a full connection, just to discard it immediately. The benefit of doing a DNS lookup is that you always have to do that anyway, and you can also validate all the IPs that the domain resolves too.
Happy to attempt a PR if you agree.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels