Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

CintermediatecliAI generated

HTTP Status Probe

Build a command-line tool in C that checks websites by speaking HTTP directly over TCP sockets, without any HTTP library. For each URL, it resolves the host name, opens a connection, sends a GET request, reads the response and reports the status code, the response size, the time it took, and a clear message when something goes wrong: a DNS failure, a refused connection or a timeout. It checks a list of URLs from a file and prints a summary. It supports plain http:// URLs, which keeps the focus on sockets rather than encryption. You'll learn getaddrinfo, sockets, timeouts with poll, reading a response that arrives in pieces, parsing the HTTP status line and headers, and building with CMake.

Estimate
~10.5h
Steps
6
Completed by
0
Proposed by
codeseed.app

POSIX · CMake

Project roadmap

  1. 01

    Set up the project and parse URLs

    ~1.5h

    Create a CMake project in C11 with warnings enabled. Write parse_url that splits a URL like http://example.com:8080/path into host, port (80 by default) and path (/ by default), rejecting other schemes such as https with a clear message. The program takes URLs as arguments, or a file with -f. Done when: the program prints the parsed parts of several test URLs and rejects invalid ones.

  2. 02

    Resolve and connect

    ~2h

    Use getaddrinfo to resolve the host (for both IPv4 and IPv6), then try each address with a non-blocking socket and connect, waiting with poll up to a timeout (default 5 seconds, set with -t). Report DNS failures with gai_strerror, and refused connections and timeouts with their own messages. Always close the socket and free the address list. Done when: connecting to a working server succeeds, and a closed port or an unknown host gives a clear error.

  3. 03

    Send the request

    ~1h

    Build an HTTP/1.1 request with the method, path, a Host header, a User-Agent, Connection: close and Accept: */*, ending with a blank line (\r\n\r\n). Handle partial writes: keep calling send until the whole request is written. Done when: a local server (for example python3 -m http.server) logs your request correctly.

  4. 04

    Read and parse the response

    ~2.5h

    Read the response in a loop with recv, using poll with the remaining time so a slow server can't hang the program, until the server closes the connection. Parse the status line (HTTP/1.1 200 OK) into the version, code and reason, find the end of the headers, and report the body size, using Content-Length when present. Measure the total time with clock_gettime. Done when: the tool prints the correct status, size and time for a local server.

  5. 05

    Check many URLs and summarize

    ~1.5h

    Read URLs from a file with -f, one per line, skipping blanks and # comments. Print one aligned line per URL: status code or error, size in bytes and time in ms. End with a summary (how many OK, how many failed) and exit with code 1 if any check failed or returned a status of 400 or more. Done when: a file with good and bad URLs produces a correct table and exit code.

  6. 06

    Test it

    ~2h

    Write a test script (run by ctest) that starts a local Python HTTP server, then checks: a 200 page, a 404, a closed port, an unknown host, and a server that accepts the connection but never answers (to test the timeout). Run the tool under valgrind to make sure there are no memory leaks. Done when: all checks pass, and valgrind reports no leaks.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~10.5h · 6 steps

Tech stack

POSIXCMake