From b9e8290a2f9c75ae61edc3c89bd0fff5c9e3a0e5 Mon Sep 17 00:00:00 2001 From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> Date: Fri, 19 Jul 2024 02:23:54 -0400 Subject: img link bug --- src/server/server_Initialization.ts | 80 +++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 35 deletions(-) (limited to 'src/server') diff --git a/src/server/server_Initialization.ts b/src/server/server_Initialization.ts index 9183688c6..c3d31e74d 100644 --- a/src/server/server_Initialization.ts +++ b/src/server/server_Initialization.ts @@ -155,41 +155,51 @@ function proxyServe(req: any, requrl: string, response: any) { }; const retrieveHTTPBody = () => { // req.headers.cookie = ''; - req.pipe(request(requrl)) - .on('error', (e: any) => { - console.log(`CORS url error: ${requrl}`, e); - response.send(`
-${e}
- `); - }) - .on('response', (res: any) => { - res.headers; - const headers = Object.keys(res.headers); - const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/; - headers.forEach(headerName => { - const header = res.headers[headerName]; - if (Array.isArray(header)) { - res.headers[headerName] = header.filter(h => !headerCharRegex.test(h)); - } else if (headerCharRegex.test(header || '')) { - delete res.headers[headerName]; - } else res.headers[headerName] = header; - if (headerName === 'content-encoding') { - wasinBrFormat = res.headers[headerName] === 'br'; - res.headers[headerName] = 'gzip'; - } - }); - res.headers['x-permitted-cross-domain-policies'] = 'all'; - res.headers['x-frame-options'] = ''; - res.headers['content-security-policy'] = ''; - // eslint-disable-next-line no-multi-assign - response.headers = response._headers = res.headers; - }) - .on('end', sendModifiedBody) - .pipe(htmlBodyMemoryStream) - .on('error', (e: any) => console.log('http body pipe error', e)); - }; + try { + const reqval = request(requrl); + req.pipe(reqval) + .on('error', (e: any) => { + console.log(`CORS url error: ${requrl}`, e); + response.send(` +${e}
+ `); + }) + .on('response', (res: any) => { + res.headers; + const headers = Object.keys(res.headers); + const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/; + headers.forEach(headerName => { + const header = res.headers[headerName]; + if (Array.isArray(header)) { + res.headers[headerName] = header.filter(h => !headerCharRegex.test(h)); + } else if (headerCharRegex.test(header || '')) { + delete res.headers[headerName]; + } else res.headers[headerName] = header; + if (headerName === 'content-encoding') { + wasinBrFormat = res.headers[headerName] === 'br'; + res.headers[headerName] = 'gzip'; + } + }); + res.headers['x-permitted-cross-domain-policies'] = 'all'; + res.headers['x-frame-options'] = ''; + res.headers['content-security-policy'] = ''; + // eslint-disable-next-line no-multi-assign + response.headers = response._headers = res.headers; + }) + .on('end', sendModifiedBody) + .pipe(htmlBodyMemoryStream) + .on('error', (e: any) => console.log('http body pipe error', e)); + } catch (e) { + console.log("Request failed: ", e); + response.send(` +${e}
+ `); + } + } retrieveHTTPBody(); } -- cgit v1.2.3-70-g09d2