How it works
Use DNS and HTTP clients with timeouts, redirect limits, response-size caps, accepted content types, and bounded decompression. A gzip response can expand about 1,000 times, so a 10 MB download may become 10 GB in memory; cap the decompressed size, not just the transfer. Set a clear crawler identity, track response status, and close sockets and streams on failure. Concurrency helps throughput, but each worker has finite memory, bandwidth, and file descriptors.
Validate destinations after every redirect and DNS resolution. This defends against SSRF (server-side request forgery), where an attacker gets your server to call addresses it can reach and they cannot. A public page could redirect to 169.254.169.254, the address where cloud instances read metadata, which may include credentials. Check the address actually connected to, because a hostname can resolve to a public address at check time and a private one moments later.
Parse HTML with a tolerant parser, not a regular expression, because real pages are often malformed. Resolve relative links using the final document URL and any valid base URL, filter unsupported schemes, and keep metadata such as status, content type, fetch time, and canonical hints. JavaScript-rendered pages require a separate, more expensive rendering path if they are in scope: a headless browser uses far more CPU and memory than parsing the same page. Google renders pages with headless Chromium in a stage after crawling. Do not render every page by default.
A fetched public URL redirects to a private IP address. What should the downloader do?
Reject that destination before connecting and record the reason. Validate each redirect and resolved address, not just the seed URL.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Bound redirects, time, bytes, decompression, and destinations.
- HTML parsing and browser rendering have different costs and coverage.