Skip to content

on_request_started callback doesn't fire on certain errors

h = HTTPX.plugin(:callbacks).on_request_started { puts "starting!" }

h.get("https://www.example.com")
# Prints "starting!"

h.get("https://www.example.commm")
# Does not print, DNS resolution error

h.with(timeout: {request_timeout: 0.0001}).get("https://www.example.com")
# Does print, request times out

I'm not sure if this is expected behavior, but it caught me out. I expected that all requests would emit the on_request_started callback, but it seems that for DNS resolution errors (and perhaps other network errors), the request never "starts". Makes sense on a network level, but this surprised me. Maybe, if this is intended behavior, it could be clarified in the documentation.