From aba32d54c0194d477dbe63c56dd98910a16b4875 Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Thu, 12 Jan 2023 11:04:28 -0500 Subject: [PATCH] Fix the cuda and microsoft compilation from /noscript (#4524) --- lib/handlers/compile.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/handlers/compile.ts b/lib/handlers/compile.ts index 475fc49e8b7..c96c9a73294 100644 --- a/lib/handlers/compile.ts +++ b/lib/handlers/compile.ts @@ -134,18 +134,30 @@ export class CompileHandler { // decoding middleware. this.proxy.on('proxyReq', (proxyReq, req) => { // TODO ideally I'd work out if this is "ok" - IncomingMessage doesn't have a body, but pragmatically the - // object we get here does. + // object we get here does (introduced by body-parser). const body = (req as any).body; if (!body || Object.keys(body).length === 0) { return; } - const contentType = proxyReq.getHeader('Content-Type'); + let contentType: string = proxyReq.getHeader('Content-Type') as string; let bodyData; if (contentType === 'application/json') { bodyData = JSON.stringify(body); } else if (contentType === 'application/x-www-form-urlencoded') { - bodyData = body; + // Reshape the form body into what a json request looks like + contentType = 'application/json'; + bodyData = JSON.stringify({ + lang: body.lang, + compiler: body.compiler, + source: body.source, + options: body.userArguments, + filters: Object.fromEntries( + ['commentOnly', 'directives', 'libraryCode', 'labels', 'demangle', 'intel', 'execute'].map( + key => [key, body[key] === 'true'], + ), + ), + }); } else { Sentry.captureException( new Error(`Unexpected Content-Type received by /compiler/:compiler/compile: ${contentType}`), @@ -156,6 +168,7 @@ export class CompileHandler { try { if (bodyData) { proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData)); + proxyReq.setHeader('Content-Type', contentType); proxyReq.write(bodyData); } } catch (e: any) {