{"id":26058895,"url":"https://github.com/zackiles/response-rewriter","last_synced_at":"2026-04-16T21:36:14.105Z","repository":{"id":278982362,"uuid":"937376719","full_name":"zackiles/response-rewriter","owner":"zackiles","description":"Strip or replace any and all instances of a string in a Response object (Fetch-based): URLs, headers, bodies, unicode, streaming, multipart, and regex support","archived":false,"fork":false,"pushed_at":"2025-02-23T00:49:26.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-29T00:26:17.690Z","etag":null,"topics":["deno","fetch","proxy","regex","rewriter"],"latest_commit_sha":null,"homepage":"https://jsr.io/@zackiles/response-rewriter","language":"TypeScript","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/zackiles.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":"2025-02-22T22:35:27.000Z","updated_at":"2025-02-23T19:36:53.000Z","dependencies_parsed_at":"2025-02-23T00:47:41.781Z","dependency_job_id":null,"html_url":"https://github.com/zackiles/response-rewriter","commit_stats":null,"previous_names":["zackiles/response-rewriter"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/zackiles/response-rewriter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fresponse-rewriter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fresponse-rewriter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fresponse-rewriter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fresponse-rewriter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zackiles","download_url":"https://codeload.github.com/zackiles/response-rewriter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fresponse-rewriter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31905889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"ssl_error","status_checked_at":"2026-04-16T18:21:47.142Z","response_time":69,"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":["deno","fetch","proxy","regex","rewriter"],"created_at":"2025-03-08T12:40:52.352Z","updated_at":"2026-04-16T21:36:14.079Z","avatar_url":"https://github.com/zackiles.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# response-rewriter\n\nDeno library for modifying Response objects by replacing text patterns in headers, bodies, and URLs. Supports streaming responses, multiple encodings, and complex Unicode scenarios. Handles even the most nightmarish of edge-cases. Perfect for rewriting Responses in proxies.\n\n[![JSR Score](https://jsr.io/badges/@zackiles/response-rewriter/score)](https://jsr.io/@zackiles/response-rewriter)\n[![JSR](https://jsr.io/badges/@zackiles/response-rewriter)](https://jsr.io/@zackiles/response-rewriter)\n[![JSR Scope](https://jsr.io/badges/@zackiles)](https://jsr.io/@zackiles)\n\n## Features\n\n- 🔄 Replace text in Response objects (headers, body, URLs)\n- 🌊 Streaming support with proper chunking\n- 🌐 Full Unicode support with proper surrogate pair handling\n- 📝 JSON-aware with circular reference detection\n- 🎭 Multipart response support\n- 📚 Comprehensive test coverage\n- 🔒 Safe header handling\n- 🚀 High performance with minimal memory usage\n\n## Installation\n\n```bash\ndeno add jsr:@zackiles/response-rewriter\n```\n\n## Usage\n\n```typescript\nimport { replaceInResponse } from \"jsr:@zackiles/response-rewriter\";\n\n// Simple string replacement\nconst response = new Response(\"Hello world!\", {\n  headers: { \"x-custom\": \"old-value\" }\n});\nconst modified = await replaceInResponse(\"world\", \"Deno\", response);\nconsole.log(await modified.text()); // \"Hello Deno!\"\nconsole.log(modified.headers.get(\"x-custom\")); // \"old-value\"\n\n// Regex with capture groups\nconst jsonResponse = new Response(JSON.stringify({\n  email: \"user@old-domain.com\",\n  nested: { value: \"prefix_old_suffix\" }\n}), {\n  headers: { \"content-type\": \"application/json\" }\n});\n\nconst regex = /(\\w+)@old-domain\\.com/;\nconst modified = await replaceInResponse(\n  regex,\n  \"$1@new-domain.com\",\n  jsonResponse\n);\n\nconst result = await modified.json();\nconsole.log(result.email); // \"user@new-domain.com\"\n```\n\n## API\n\n### replaceInResponse(search, replacement, response)\n\nReplaces all occurrences of a pattern in both headers and body of an HTTP response.\n\n#### Parameters\n\n- `search` (string | RegExp): The text or regex pattern to search for\n- `replacement` (string): The replacement text\n- `response` (Response): The original HTTP response to modify\n\n#### Returns\n\n- Promise\u003cResponse\u003e: A new Response object with the replacements applied\n\n## Advanced Features\n\n### Streaming Support\n\nThe library properly handles chunked transfer encoding and streaming responses:\n\n```typescript\nconst stream = new ReadableStream({\n  start(controller) {\n    controller.enqueue('Hello ');\n    controller.enqueue('world!');\n    controller.close();\n  }\n});\n\nconst response = new Response(stream, {\n  headers: { \"transfer-encoding\": \"chunked\" }\n});\n\nconst modified = await replaceInResponse(\"world\", \"Deno\", response);\n// Streams the response with replacements\n```\n\n### Unicode \u0026 Surrogate Pairs\n\nProperly handles complex Unicode scenarios including surrogate pairs:\n\n```typescript\nconst response = new Response(\n  \"Hello 🌎!\", // Uses surrogate pairs\n  { headers: { \"content-type\": \"text/plain; charset=utf-8\" }}\n);\n\nconst modified = await replaceInResponse(\"🌎\", \"🦕\", response);\nconsole.log(await modified.text()); // \"Hello 🦕!\"\n```\n\n### JSON Processing\n\nIntelligently processes JSON content with circular reference protection:\n\n```typescript\nconst obj = { name: \"old\" };\nobj.self = obj; // Circular reference\n\nconst response = new Response(JSON.stringify(obj), {\n  headers: { \"content-type\": \"application/json\" }\n});\n\nconst modified = await replaceInResponse(\"old\", \"new\", response);\n// Safely handles circular references\n```\n\n## License\n\nMIT - See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackiles%2Fresponse-rewriter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackiles%2Fresponse-rewriter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackiles%2Fresponse-rewriter/lists"}