192
runtime.state.githubToken = newToken;
193
},
195
>
if (disposed) {
196
return;
197
}
199
>
release();
200
>
},
201
>
};
202
>
}
203
204
protected override async handleRequest(
206
>
res: http.ServerResponse,
207
>
runtime: ICodexProxyRuntime,
208
>
): Promise<void> {
209
>
const method = req.method ?? 'GET';
210
>
const pathname = new URL(req.url ?? '/', 'http://127.0.0.1').pathname;
211
>
const incomingHeaders = Object.keys(req.headers).join(', ');
212
>
this._logService.info(`[${PROXY_USER_FACING_NAME}] >>> ${method} ${pathname} (headers: ${incomingHeaders})`);
213
>
214
>
if (method === 'GET' && pathname === '/') {
215
res.writeHead(200, { 'Content-Type': 'text/plain' });
216
res.end('ok');
217
return;
218
}
220
>
// Codex CLI sends `Bearer <nonce>` — plain nonce, no sessionId suffix.
221
>
const authHeader = req.headers['authorization'];
222
>
const expected = `Bearer ${runtime.nonce}`;
223
>
if (typeof authHeader !== 'string' || authHeader !== expected) {
224
writeJsonError(res, 401, 'authentication_error', 'Invalid authentication');
225
return;
226
}
228
>
if (method === 'GET' && pathname === '/v1/models') {
229
// The Codex endpoint expects its own rich `ModelsResponse` schema, not
230
// CAPI's model shape. VS Code already owns CAPI model discovery and