projectdiscovery / httpx

httpx is a fast and multi-purpose HTTP toolkit that allows running multiple probes using the retryablehttp library.
https://docs.projectdiscovery.io/tools/httpx
MIT License
7.53k stars 822 forks source link

Exit code 0 on timeout #1877

Closed boffman closed 1 month ago

boffman commented 1 month ago

httpx version:

v1.6.8

Current Behavior:

Running httpx against a single host with -u, which times out, still returns exit code 0.

Expected Behavior:

I would expect this to return with a non-zero exit code, indicating that the tool failed somehow.

Steps To Reproduce:

Run:

httpx -u https://xxxx -title -tech-detect -status-code -d ..where xxxx is a host that times out.

Notice the DBG message indicating a failure due to timeout:

[DBG] Failed 'https://xxxx': GET https://xxxx giving up after 1 attempts: Get "https://xxxx": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

And yet the exit code is zero, which normally indicates success:

$ echo $?
0

Anything else:

I use this on a per-host basis with -u from a script and would like to be able to detect that the tool got a timeout (or any other error). Checking the exit code if it's other than zero feels like a pretty standard way to do this.

tarunKoyalwar commented 1 month ago

@boffman , while it may be a valid use case httpx is primarily used with multiple hosts to check which of those are live . and timeout error is a common error which can either happen due to timeout value being low or some firewall blocking issue or some other network issue.

returning non zero status code will break existing automations in place that currently use httpx, and this will be a big breaking change so i suggest you handle this manually by using verbose flag and looking for errors from stderr or simply use httpx as library