Skip to content

Commit 26191b7

Browse files
committed
Preserve UTF-8 encoding for agent guide
1 parent c113386 commit 26191b7

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎scripts/orbit-slice1-worker-tests.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ function assetBinding(): NonNullable<OrbitBindings['ASSETS']> {
6060
headers: { 'content-type': 'text/plain; charset=utf-8' },
6161
});
6262
}
63+
if (path === '/skill.md') {
64+
return new Response('# Ajan katılım rehberi\n\nTürkçe karakterler: ğüşöçıİ', {
65+
headers: { 'content-type': 'text/markdown' },
66+
});
67+
}
6368
return new Response('<!doctype html><title>Orbit</title>', {
6469
headers: { 'content-type': 'text/html; charset=utf-8' },
6570
});
@@ -268,6 +273,14 @@ describe('Orbit V6 deployment-mode contract', () => {
268273
assert.match(await robots.text(), /Allow: \//u);
269274
});
270275

276+
test('serves the machine guide with an explicit UTF-8 charset', async () => {
277+
const env = productionBindings('live');
278+
const response = await worker.fetch(new Request(`${LIVE_ORIGIN}/skill.md`), env);
279+
assert.equal(response.status, 200);
280+
assert.equal(response.headers.get('content-type'), 'text/markdown; charset=utf-8');
281+
assert.match(await response.text(), /Türkçe karakterler: ğüşöçıİ/u);
282+
});
283+
271284
test('applies dashboard privacy and frame protection to GET and HEAD', async () => {
272285
const env = productionBindings('live');
273286
for (const method of ['GET', 'HEAD']) {

‎src/worker.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ function denyAllRobots(): Response {
4242
});
4343
}
4444

45+
function preserveMachineGuideEncoding(request: Request, response: Response): Response {
46+
if (new URL(request.url).pathname !== '/skill.md') return response;
47+
const encodedResponse = new Response(response.body, response);
48+
encodedResponse.headers.set('content-type', 'text/markdown; charset=utf-8');
49+
return encodedResponse;
50+
}
51+
4552
async function startStagingOAuth(request: Request, env: OrbitBindings): Promise<Response> {
4653
const apiRequest = new Request(new URL('/v1/auth/github/start', request.url), {
4754
method: 'POST',
@@ -114,7 +121,7 @@ export async function handleWorkerRequest(
114121
dependencies.publicRepository ?? new D1PublicRepository(env.DB),
115122
);
116123
if (publicPage) return publicPage;
117-
return await env.ASSETS.fetch(request);
124+
return preserveMachineGuideEncoding(request, await env.ASSETS.fetch(request));
118125
}, env.ORBIT_ENVIRONMENT);
119126
return protectFromIndexing(response, env);
120127
}

0 commit comments

Comments
 (0)