{"id":49553011,"url":"https://github.com/avvertix/caddy-content-negotiation","last_synced_at":"2026-05-03T00:31:35.873Z","repository":{"id":353636751,"uuid":"1184532777","full_name":"avvertix/caddy-content-negotiation","owner":"avvertix","description":"Content negotiation module for serving to AI Agents","archived":false,"fork":false,"pushed_at":"2026-04-24T18:54:58.000Z","size":78,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-24T20:33:11.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avvertix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-17T17:19:16.000Z","updated_at":"2026-04-24T18:40:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/avvertix/caddy-content-negotiation","commit_stats":null,"previous_names":["avvertix/caddy-content-negotiation"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/avvertix/caddy-content-negotiation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avvertix%2Fcaddy-content-negotiation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avvertix%2Fcaddy-content-negotiation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avvertix%2Fcaddy-content-negotiation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avvertix%2Fcaddy-content-negotiation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avvertix","download_url":"https://codeload.github.com/avvertix/caddy-content-negotiation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avvertix%2Fcaddy-content-negotiation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32554062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T00:31:16.350Z","status":"ssl_error","status_checked_at":"2026-05-03T00:31:15.546Z","response_time":132,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-03T00:31:35.414Z","updated_at":"2026-05-03T00:31:35.868Z","avatar_url":"https://github.com/avvertix.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Content Negotiation module for Caddy\n\nA Caddy middleware module that intercepts HTTP requests containing `Accept: text/markdown` and serves precomputed `.md` files located alongside the originally requested resources.\n\n## How It Works\n\nWhen a client sends a request with `Accept: text/markdown` (or `text/x-markdown`) in the header, this middleware:\n\n1. Determines which `.md` file corresponds to the requested path\n2. Checks if that `.md` file exists on disk\n3. If found, serves the markdown content with `Content-Type: text/markdown; charset=utf-8`\n4. If not found, passes the request to the next handler as normal (or returns `406` in strict mode)\n\nWhen `strict_mode` is enabled, the middleware also rejects requests whose `Accept` header contains only types incompatible with text content (e.g. `image/png`) with `406 Not Acceptable`, before any file lookup takes place.\n\n### Path Resolution Examples\n\n| Request Path | Markdown File Checked |\n|---|---|\n| `/docs/page.html` | `/docs/page.md` |\n| `/docs/page.php` | `/docs/page.md` |\n| `/docs/` | `/docs/index.md` |\n| `/about` | `/about.md` |\n| `/` | `/index.md` |\n\n## Installation\n\n### Using xcaddy\n\nBuild Caddy with this module using `xcaddy`:\n\n```bash\nxcaddy build --with github.com/avvertix/caddy-content-negotiation\n```\n\n### Using Docker\n\nA sample Docker setup is included. It builds a custom Caddy image with the\nmodule baked in and serves the demo content in `docker/content/`.\n\n```bash\n# Build and start\ndocker compose up --build\n\n# Test content negotiation\ncurl -H \"Accept: text/markdown\" http://localhost/\ncurl -H \"Accept: text/markdown\" http://localhost/docs/page.html\ncurl -H \"Accept: text/markdown\" http://localhost/about\n```\n\nTo use your own content, mount a volume over `/srv` in `docker-compose.yml`\nor copy files into `docker/content/` before building.\n\n## Caddyfile Configuration\n\n### Minimal\n\n`markdown_intercept` is not a standard ordered directive, so you must register\nits position in the global options block:\n\n```caddyfile\n{\n    order markdown_intercept before file_server\n}\n\nexample.com {\n    markdown_intercept\n    file_server\n}\n```\n\n### Full Options\n\n```caddyfile\n{\n    order markdown_intercept before file_server\n}\n\nexample.com {\n    markdown_intercept {\n        root /var/www/html\n        index_names index.html index.htm index.php\n        extensions .html .htm .php .txt\n        experimental_range_requests\n        strict_mode\n    }\n    file_server\n}\n```\n\n### Directives\n\n| Directive | Default | Description |\n|---|---|---|\n| `root` | Site root (`{http.vars.root}`) | Filesystem path to look for `.md` files |\n| `index_names` | `index.html index.htm index.php` | Index filenames to try for directory requests |\n| `extensions` | `.html .htm .php .txt` | File extensions eligible for `.md` substitution |\n| `experimental_range_requests` | disabled | Enable the `x-frontmatter` range unit (see below) |\n| `strict_mode` | disabled | Reject unsupported `Accept` types with `406` (see below) |\n\n## JSON Configuration\n\n```json\n{\n  \"handler\": \"markdown_intercept\",\n  \"root\": \"/var/www/html\",\n  \"index_names\": [\"index.html\", \"index.htm\"],\n  \"extensions\": [\".html\", \".htm\", \".php\"],\n  \"experimental_range_requests\": true,\n  \"strict_mode\": true\n}\n```\n\n## Client Usage\n\nRequest markdown from any endpoint by setting the `Accept` header:\n\n```bash\n# Get the markdown version of a page\ncurl -H \"Accept: text/markdown\" https://example.com/docs/page.html\n\n# Normal requests are unaffected\ncurl https://example.com/docs/page.html\n```\n\n### Frontmatter range requests (experimental)\n\nWhen `experimental_range_requests` is enabled, clients can request only the\nfrontmatter block of a markdown file using the non-standard `x-frontmatter`\n[range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Range_requests) unit:\n\n```bash\ncurl -H \"Accept: text/markdown\" \\\n     -H \"Range: x-frontmatter\" \\\n     https://example.com/docs/page.html\n```\n\nThe server responds with `206 Partial Content` and only the frontmatter section\n(the content between the opening and closing `---` delimiters). If the file has\nno frontmatter block, the server returns `416 Range Not Satisfiable`.\n\nWhen the feature is enabled, every markdown response includes\n`Accept-Ranges: x-frontmatter` so clients can discover support before issuing a\nrange request.\n\n### Strict content-type negotiation\n\nWhen `strict_mode` is enabled the middleware enforces two rules:\n\n**1. Unsupported `Accept` types are rejected with `406 Not Acceptable`**\n\nIf the request's `Accept` header contains only types outside the `text/*` family\nand no `*/*` wildcard, the middleware returns `406` immediately without\nperforming any file lookup or calling the next handler. This rejects probes and\nrequests for content the server cannot produce for text-based resources:\n\n```bash\n# Rejected — not a text type\ncurl -i -H \"Accept: image/png\" https://example.com/docs/page.html\n# → 406 Not Acceptable\n\ncurl -i -H \"Accept: application/x-content-negotiation-probe\" https://example.com/about\n# → 406 Not Acceptable\n```\n\nRequests that include at least one compatible type are allowed through:\n\n```bash\n# Allowed — text/html matches text/*\ncurl -i -H \"Accept: text/html, application/json\" https://example.com/docs/page.html\n\n# Allowed — wildcard covers everything\ncurl -i -H \"Accept: */*\" https://example.com/docs/page.html\n```\n\n**2. Missing markdown files return `406` instead of passing through**\n\nWhen the client explicitly requests `text/markdown` but no `.md` file exists for\nthe requested path, the middleware returns `406` rather than forwarding the\nrequest to the next handler:\n\n```bash\n# 406 if /docs/page.md does not exist\ncurl -i -H \"Accept: text/markdown\" https://example.com/docs/page.html\n```\n\nWithout `strict_mode` the same request would be forwarded to the next handler\n(e.g. a file server that serves the HTML version), and the `X-Content-Md:\nrequested` header would be added to the forwarded request.\n\n## Response Headers\n\nWhen a markdown file is served, the response includes:\n\n- `Content-Type: text/markdown; charset=utf-8`\n- `Accept-Ranges: x-frontmatter` (only when `experimental_range_requests` is enabled)\n\nA `206 Partial Content` frontmatter response additionally includes:\n\n- `Content-Range: x-frontmatter 0-\u003cend\u003e/\u003ctotal\u003e` — byte offsets of the frontmatter block within the full file\n\n## Development\n\n```bash\n# Run tests\ngo test -v -race ./...\n\n# Build Caddy locally with the module (requires xcaddy)\nxcaddy build --with github.com/avvertix/caddy-content-negotiation=.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favvertix%2Fcaddy-content-negotiation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favvertix%2Fcaddy-content-negotiation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favvertix%2Fcaddy-content-negotiation/lists"}