Representative interview topic

General Interview: What Should an HTTP 451 Response Contain, and How Should Clients Handle It?

GeneralMedium
Offer.cc Editorial TeamPublished Updated

Question

Your content service must deny a resource because of a court order or regional regulation. An interviewer asks whether you should return HTTP 451 and how to design the body, Link header, caching, and client behavior. How would you answer?

Prompt and context

This networking and API fundamentals prompt fits backend, platform, and infrastructure roles. A resource is denied because of a legal requirement, and the block may occur at the origin, CDN, ISP, or search engine. The goal is to explain when 451 is appropriate, how to provide transparency, and why a legal block is not an ordinary permission error or retryable outage.

What the interviewer is assessing

  • Can you distinguish 451, 403, 404, and 5xx by semantics and responsibility?
  • Do you know that 451 signals a legal demand without proving that the resource exists?
  • Can you combine the response body, Link: rel="blocked-by", caching, and proxy behavior correctly?
  • Do you consider privacy, misleading disclosures, client usability, audit logs, and multi-region verification?

Clarifying questions to ask

Confirm who actually enforces the block, whether the result varies by region, whether the legal basis may be disclosed, whether a shared cache sits in front, and whether the client is a browser, mobile app, or API consumer. If the user simply lacks permission, use 401 or 403; if the resource is absent, do not change it to 451 merely to hide implementation details. If disclosure is prohibited, define public and internal evidence separately.

A 30-second answer framework

I would use 451 only when the service is denying access because of a legal demand, and put the legal basis and scope in an auditable body. If a CDN or another intermediary enforces the block, Link with rel="blocked-by" identifies the entity doing it, not the authority that issued the demand. I would choose cache behavior based on regional and policy volatility, show clients a clear unavailable state, and avoid automatic retries or promises that a different network will work. Finally I would verify origin, proxy, cache, and regional behavior together.

Step-by-step deep dive

  1. Classify the semantics. 451 means the server denies a resource because of a legal demand; 403 means the identified requester is not allowed, and 404 means the resource is absent or its existence is intentionally hidden. 451 does not prove that the resource exists and is not a technical failure.
  2. Identify the enforcing entity. The origin, CDN, ISP, DNS service, or search engine may be the actual blocker. That entity identifies itself in a Link header with rel="blocked-by"; the authority or policy explanation belongs in the body or policy page, not in that relation.
  3. Design the response. Explain the legal or policy basis, issuing party, affected region or resource class, and an appeal or help path. If disclosure creates additional risk, publish only what is necessary while retaining the full basis and approver in internal audit records.
  4. Handle caching. RFC 7725 permits 451 to be cached by default, so a frequently changing legal or regional state needs explicit Cache-Control, a short TTL, or no-store. A shared-cache key must include every dimension that affects the block so one region’s answer cannot leak to another.
  5. Define client behavior. A browser shows a clear content-restricted state. An API client treats 451 as a non-retryable policy error, preserving the status, blocking details, and request ID. It should not rewrite it as 500 or automatically route around the policy through a proxy or VPN.
  6. Verify and monitor. Compare status, body, headers, and cache hits from origin-direct, CDN, multiple regions, cache-warm and cache-cold requests, and different clients. Record audit events, rule versions, enforcing entity, and revocation time; purge affected caches when policy changes.

Example of a strong answer

I would first confirm that the denial is genuinely legal. A permission problem returns 403 and a missing resource returns 404; 451 communicates a legal block without asserting that the resource exists. Because the origin or CDN may enforce it, I would identify the actual blocker in Link:

http
HTTP/1.1 451 Unavailable For Legal Reasons
Content-Type: application/problem+json
Cache-Control: private, max-age=300
Link: <https://blocker.example/policy/123>; rel="blocked-by"

{
  "status": 451,
  "title": "Unavailable For Legal Reasons",
  "detail": "Access is restricted in this region under the cited policy.",
  "policy_id": "policy-123",
  "request_id": "req-7f2"
}

The body gives the user enough explanation and an appeal path; internal audit retains the full legal basis, regional decision, rule version, and operator. Since 451 is cacheable by default, the cache key includes region and rule version, with a short TTL or no storage when policy state changes quickly. The client presents a policy restriction and stops automatic retries. Tests cover origin, CDN, cache hits, region changes, rule revocation, and cases where disclosure is limited.

Common mistakes

  • Returning 451 for every denial → permissions, absence, and legal blocks become indistinguishable → classify the reason before choosing 401, 403, 404, 451, or 5xx.
  • Putting the legal authority in blocked-by → the relation’s semantics are wrong → identify the enforcing entity there and explain policy separately in the body.
  • Ignoring default cacheability → one region’s result is shared with another → design the cache key, TTL, and any required no-store behavior.
  • Automatically retrying 451 → repeated requests cannot change policy state → treat it as a non-retryable policy error with actionable help text.
  • Treating 451 as proof that a resource exists → it can leak site information → state explicitly that the status does not establish existence.

Follow-up questions and answers

What if the legal demand forbids disclosing the exact provision?

Return only the necessary restriction and request ID; do not invent details. Keep the legal basis, approver, and version in internal audit records. The client should still know it is a policy restriction rather than a network failure.

Can a 451 response be cached?

Yes. RFC 7725 says it is cacheable by default, but volatility and sensitivity determine the policy. If region, user group, or rule version changes the result, use the right cache key and a short TTL, possibly no-store, and purge caches when the block is revoked.

The CDN returns 451 while the origin returns 200. Which is the blocker?

The CDN is the entity actually denying the request and should appear in blocked-by; the origin log should show that it did not perform that block. Verify origin-direct, CDN, and cache states separately so the layers are not conflated.

Public sources

Related questions