Skip to content

SWF(refactor): build the Worker's post response only once - #813

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1795145877-worker-single-response
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1795145877-worker-single-response

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Worker now builds each post response once instead of re-wrapping it per header tweak; served output is byte-for-byte unchanged.

Before, a negotiated Markdown request copied the headers and created a new Response twice (addVaryAccept(addMarkdownCharset(response))). Now addMarkdownCharset / addVaryAccept edit one shared Headers, and fetch makes a single final Response:

const response = await env.ASSETS.fetch(isMarkdown ? markdownRequest : request);
if (!isNegotiable && !needsMarkdownCharset) return response; // other routes are passed through untouched, as before
const headers = new Headers(response.headers);
if (needsMarkdownCharset) addMarkdownCharset(headers);
if (isNegotiable) addVaryAccept(headers);
return new Response(response.body, { status, statusText, headers });

Only src/worker.ts changes (+25/−27). Tests are unchanged.

Evidence

Real wrangler dev (real wrangler.toml + built dist), same probe run against main and against this branch. diff before.txt after.txt shows no difference (headers and body SHA-1 match):

== GET /posts/audio-interface-under-the-desk/ Accept: text/html
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Vary: Accept
fe71efd21c26
== GET /posts/audio-interface-under-the-desk/ Accept: text/markdown
HTTP/1.1 200 OK
Content-Type: text/markdown; charset=utf-8
Vary: Accept
d24f6df29e0c
== HEAD /posts/audio-interface-under-the-desk Accept: text/markdown
HTTP/1.1 200 OK
Content-Type: text/markdown; charset=utf-8
Vary: Accept
== GET /posts/audio-interface-under-the-desk.md Accept: */*
HTTP/1.1 200 OK
Content-Type: text/markdown; charset=utf-8
d24f6df29e0c
== GET /about/ Accept: text/html
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
2bda2d17231e

Results on this branch: pnpm run test:worker passed 73/73. pnpm run test:integration (Wrangler test harness) passed 7/7. pnpm run lint showed 0 errors.

Try it: pnpm run build:ci && pnpm wrangler dev then curl -sI -H 'Accept: text/markdown' localhost:8787/posts/audio-interface-under-the-desk

Untested: there is no UI change, so no screenshots. I did not check this on a production deploy.


Software Factory opened this PR for Daiki
Implemented in session Build Worker markdown Response only once
Review with Devin · Open in Devin Desktop


Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a1b37691-d747-4e9d-9bf1-377ec4bd766e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
blog 171d76b Commit Preview URL

Branch Preview URL
Nov 20 2026, 03:40 AM

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

QA結果: PASS(171d76b)

main の Worker と PR の Worker を、同じビルド成果物(merge-base でビルドした dist)でローカルの wrangler dev に並べて立て、同じリクエストを送って比べました。

確かめたこと

  • 記事 URL の HTML、Accept: text/markdown で取った Markdown、直接取った .md で、ステータス・全ヘッダー(Content-Type、Vary、ETag)・本文が main とバイト単位で一致しました。
    • 26 通りのリクエスト(Accept の q 値の違い、末尾スラッシュなし、HEAD、POST、存在しない記事、/posts/ 以外のパス)
    • 全 17 記事 × HTML と Markdown
    • If-None-Match による 304 と Range ヘッダー付きのリクエスト
  • 主な値: HTML は text/html; charset=utf-8 と Vary: Accept、Markdown は text/markdown; charset=utf-8 と Vary: Accept、直接の .md は text/markdown; charset=utf-8 で Vary なし。
  • ブラウザ(Chrome): 記事の表示は main と同じでした。PR 側で記事からブログのトップへ移動でき、直接開いた .md も文字化けせず、存在しない記事では 404 ページが出ました。
  • pnpm run test:worker: 73 件すべて成功。

確かめていないこと

  • 本番とプレビューのデプロイは確かめていません(ローカルの wrangler dev だけです)。
  • ブラウザで開いた記事にはコードブロックがなく、コードブロックの表示はブラウザでは見ていません(本文の一致は全記事で確かめています)。

補足

  • 別々のフォルダで立てた wrangler dev 同士では、Worker を通らないパス(/ や /rss.xml)でも ETag が違いました。そのため、同じフォルダから main と PR の Worker を立てて比べています。PR による差ではありません。
main と PR の記事 ヘッダーと Markdown の比較
記事の比較 ヘッダーと Markdown

ブラウザ確認の録画

録画(チャプター付き)

Written by Devin

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants