Curl head vs get header debugging

From divinevideo/divine-mobile · View interactive version

Curl head vs get header debugging is an AI agent skill from the GitHub repository divinevideo/divine-mobile. Fix misleading HTTP response header values when debugging with curl -I or curl -sI. Use when: (1) Response headers differ between curl testing and actual browser/client behavior, (2) Cache-Control or other headers show unexpected values despite correct middleware code, (3) Server-side middleware tha

How to use this skill

Skill file

curl -I Sends HEAD, Not GET — Header Debugging Trap

Problem

When debugging HTTP response headers with curl -I or curl -sI, the response may show

different header values than what actual GET requests receive. This is because -I sends

a HEAD request, and server middleware that only processes GET requests will be skipped.

Context / Trigger Conditions

Solution

Use curl -s -D - -o /dev/null instead of curl -I to get response headers from a GET request:

# WRONG — sends HEAD request, middleware may skip processing
curl -sI https://example.com/api/endpoint

# CORRECT — sends GET request, dumps headers, discards body
curl -s -D - -o /dev/null https://example.com/api/endpoint

If you need just specific headers:

curl -s -D - -o /dev/null https://example.com/api/endpoint | grep -iE 'cache-control|surrogate'

Verification

Compare output from both methods:

echo "=== HEAD (curl -I) ===" 
curl -sI https://example.com/api/endpoint | grep cache-control

echo "=== GET (curl -D) ==="
curl -s -D - -o /dev/null https://example.com/api/endpoint | grep cache-control

If the values differ, your middleware has a GET-only guard (which is correct behavior).

Example

Axum middleware that only sets cache headers for GET requests:

async fn cache_middleware(request: Request, next: Next) -> Response {
    let method = request.method().clone();
    let mut response = next.run(request).await;
    
    // HEAD requests skip this — curl -I won't see these headers!
    if method != Method::GET {
        return response;
    }
    
    response.headers_mut().insert("cache-control", ...);
    response.headers_mut().insert("surrogate-control", ...);
    response
}

Notes

often don't replicate this because HEAD is rarely used by CDNs or browsers for caching decisions.

even if curl -I shows different headers.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.