fix: append router revision link to HTML footers#30
Conversation
|
Warning @Ductrung03 this pull request must be linked to an open issue and target the repository's default branch, or it will get automatically closed. |
📝 WalkthroughWalkthroughThis PR adds git revision footer injection to HTML responses in the proxy worker. A new 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| async function withFooterRevision(response: Response): Promise<Response> { | ||
| const contentType = response.headers.get('content-type') || '' | ||
| if (!/\btext\/html\b/i.test(contentType)) return response | ||
|
|
||
| const html = await response.text() | ||
| const rewritten = injectFooterRevision(html) | ||
| const headers = new Headers(response.headers) | ||
| if (rewritten !== html) headers.delete('content-length') | ||
|
|
There was a problem hiding this comment.
Skip footer rewrite when the upstream response has no body.
withFooterRevision rewrites any text/html response, but body-less responses (e.g., HEAD/204/304) are converted into synthetic footer HTML. That changes HTTP semantics and can drop expected headers.
Suggested fix
async function withFooterRevision(response: Response): Promise<Response> {
const contentType = response.headers.get('content-type') || ''
if (!/\btext\/html\b/i.test(contentType)) return response
+ if (response.body === null || response.status === 204 || response.status === 304) {
+ return response
+ }
const html = await response.text()
const rewritten = injectFooterRevision(html)
const headers = new Headers(response.headers)
if (rewritten !== html) headers.delete('content-length')📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| async function withFooterRevision(response: Response): Promise<Response> { | |
| const contentType = response.headers.get('content-type') || '' | |
| if (!/\btext\/html\b/i.test(contentType)) return response | |
| const html = await response.text() | |
| const rewritten = injectFooterRevision(html) | |
| const headers = new Headers(response.headers) | |
| if (rewritten !== html) headers.delete('content-length') | |
| async function withFooterRevision(response: Response): Promise<Response> { | |
| const contentType = response.headers.get('content-type') || '' | |
| if (!/\btext\/html\b/i.test(contentType)) return response | |
| if (response.body === null || response.status === 204 || response.status === 304) { | |
| return response | |
| } | |
| const html = await response.text() | |
| const rewritten = injectFooterRevision(html) | |
| const headers = new Headers(response.headers) | |
| if (rewritten !== html) headers.delete('content-length') | |
Summary
Verification
Note: bun run type-check could not run locally because
tscwas not available in this clone.B. Đợi maintainer duyệt