(request, response)
| 78 | server.listen(requestedPort); |
| 79 | |
| 80 | async function requestHandler(request, response) { |
| 81 | const url = parseURL(request.url); |
| 82 | const filePath = unescape(url.pathname); |
| 83 | |
| 84 | if (url.search === '?send_delayed' && delayResolve) { |
| 85 | delayResolve(); |
| 86 | delayResolve = null; |
| 87 | } |
| 88 | |
| 89 | if (filePath === '/') { |
| 90 | const landingURL = `http://localhost:${remoteDebuggingPort}#custom=true`; |
| 91 | sendResponse(200, `<html>Please go to <a href="${landingURL}">${landingURL}</a></html>`, 'utf8'); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | if (filePath === '/v1/records:queryRecord') { |
| 96 | try { |
| 97 | const body = JSON.parse(await readRequestBody(request)); |
| 98 | const {origin, url} = body; |
| 99 | const basename = parseURL(origin || url).hostname; |
| 100 | const absoluteFilePath = path.join(devtoolsFolder, `test/e2e/resources/performance/${basename}.rawresponse`); |
| 101 | try { |
| 102 | const responseContents = await readFile(absoluteFilePath, 'utf8'); |
| 103 | const {statusCode, data, headers} = parseRawResponse(responseContents); |
| 104 | sendResponse(statusCode || 200, data, 'utf8', headers); |
| 105 | } catch (err) { |
| 106 | console.error(`Unable to read local file ${absoluteFilePath}:`, err); |
| 107 | sendResponse(500, '500 - Internal Server Error', 'utf8'); |
| 108 | } |
| 109 | } catch (err) { |
| 110 | console.error(`Unable to handle request to ${filePath}:`, err); |
| 111 | sendResponse(500, '500 - Internal Server Error', 'utf8'); |
| 112 | } |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | const absoluteFilePath = path.join(devtoolsFolder, filePath); |
| 117 | if (!path.resolve(absoluteFilePath).startsWith(path.join(devtoolsFolder, '..'))) { |
| 118 | console.log(`File requested (${absoluteFilePath}) is outside of devtools folder: ${devtoolsFolder}`); |
| 119 | sendResponse(403, `403 - Access denied. File requested is outside of devtools folder: ${devtoolsFolder}`, 'utf8'); |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | const fileExists = await exists(absoluteFilePath); |
| 124 | if (!fileExists) { |
| 125 | console.log(`Cannot find file ${absoluteFilePath}. Requested URL: ${filePath}`); |
| 126 | sendResponse(404, '404 - File not found', 'utf8'); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | let statusCode, data, headers; |
| 131 | const headersFileExists = await exists(absoluteFilePath + '.headers'); |
| 132 | if (headersFileExists) { |
| 133 | try { |
| 134 | const headersFile = await readFile(absoluteFilePath + '.headers', 'utf8'); |
| 135 | ({statusCode, headers} = parseRawResponse(headersFile)); |
| 136 | } catch (err) { |
| 137 | console.log(`Unable to read local file ${absoluteFilePath}.headers:`, err); |
nothing calls this directly
no test coverage detected