ASCII HTTP header boundaries
One extra line can change a header’s meaning. HeaderAnvil is a coding workspace for following header input through validation and formatting, with proposed changes available for review.
import re
TOKEN = re.compile(r"[!#$%&'*+.^_`|~0-9A-Za-z-]+")
def header_line(name, value):
if not isinstance(name, str) or not TOKEN.fullmatch(name):
raise ValueError("header name")
if not isinstance(value, str) or any(not 32 <= ord(c) <= 126 for c in value):
raise ValueError("ASCII header value")
return name + ": " + value| Project | Reject invalid name characters, line breaks, controls and non-ASCII input, allowing an empty value without creating an extra header. |
|---|---|
| Review before applying | Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes. |
| Connection | Base URL, credentials and a reachable server. |
import re
TOKEN = re.compile(r"[!#$%&'*+.^_`|~0-9A-Za-z-]+")
def header_line(name, value):
if not isinstance(name, str) or not TOKEN.fullmatch(name):
raise ValueError("header name")
if not isinstance(value, str) or any(not 32 <= ord(c) <= 126 for c in value):
raise ValueError("ASCII header value")
return name + ": " + valueGive request-building code a clear input boundary
HeaderAnvil brings request-building work into a Windows coding workspace with a connected AI conversation. Start by naming the header your application needs to construct and the values it should accept. That turns a general request to strengthen validation into a reviewable change at a specific boundary in the source.
For example, you might ask the assistant to examine the supplied ASCII header formatter alongside your actual client code. Its name and value checks give the discussion concrete material, but they do not define every HTTP use case. Explain the input contract your application requires before asking for broader acceptance or stricter rejection.
Next, review where the proposed check runs and how its failure reaches the caller. A rejected value is useful only if the surrounding request path handles that outcome deliberately. Test normal input and prohibited characters with your project's own fixtures, then inspect the resulting request construction and error reporting before considering the task complete.
An unrestricted AI model may support this work when available from a supported OpenAI-compatible or Anthropic endpoint. Configure the endpoint and required credentials, and account for model-specific context limits and tool support. Its label does not remove provider restrictions or establish that a suggested validator matches your application's protocol requirements.
Questions about changing header construction
- What contract should I state for a custom header?
Name the accepted characters, empty-value policy and expected failure behavior for your application. Include the code that consumes the formatted line. Do not ask the model to infer a complete protocol policy from one example value.
- Can the ASCII example be treated as a universal HTTP validator?
No. It illustrates a deliberately narrow source-level contract. Review the requirements of the client and protocol path you actually use before extending it, and test changes against that implementation rather than assuming universal compatibility.
- Where should I check how invalid input is reported?
Follow the formatter's caller through request creation and error handling. Ask whether a failure stops the request, becomes a user-visible message or is logged. Review the proposed behavior at that boundary as well as inside validation.
- How can I share a failing request without sending credentials?
Replace secret values with representative placeholders that preserve the relevant characters and structure. Include the construction code and observed failure. The selected model needs the validation case, not the live authorization value from your service.
HeaderAnvil · Updated 2026-10-25