1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 11:24:35 +00:00

fix(stp): return plain/text header for GET & debug

This commit is contained in:
Saad Jutt
2022-03-14 04:42:30 +05:00
parent 698180ab7e
commit 145ac45036
4 changed files with 23 additions and 7 deletions

View File

@@ -14,6 +14,7 @@ import {
generateFileUploadSasCode,
getTmpFilesFolderPath,
HTTPHeaders,
isDebugOn,
sasJSCoreMacros
} from '../../utils'
@@ -160,9 +161,6 @@ ${program}`
: await readFile(weboutPath)
: ''
const debugValue =
typeof vars._debug === 'string' ? parseInt(vars._debug) : vars._debug
// it should be deleted by scheduleSessionDestroy
session.inUse = false
@@ -170,8 +168,7 @@ ${program}`
return {
httpHeaders,
webout,
log:
(debugValue && debugValue >= 131) || session.crashed ? log : undefined
log: isDebugOn(vars) || session.crashed ? log : undefined
}
}
@@ -179,7 +176,7 @@ ${program}`
httpHeaders,
result: fileResponse
? webout
: (debugValue && debugValue >= 131) || session.crashed
: isDebugOn(vars) || session.crashed
? `<html><body>${webout}<div style="text-align:left"><hr /><h2>SAS Log</h2><pre>${log}</pre></div></body></html>`
: webout
}

View File

@@ -21,6 +21,7 @@ import { PreProgramVars } from '../types'
import {
getTmpFilesFolderPath,
HTTPHeaders,
isDebugOn,
LogLine,
makeFilesNamesMap,
parseLogToArray
@@ -62,7 +63,9 @@ export class STPController {
* The response headers can be adjusted using the mfs_httpheader() macro. Any
* file type can be returned, including binary files such as zip or xls.
*
* This behaviour differs for POST requests, in which case the reponse is
* If _debug is >= 131, response headers will contain Content-Type: 'text/plain'
*
* This behaviour differs for POST requests, in which case the response is
* always JSON.
*
* @summary Execute Stored Program, return raw _webout content.
@@ -140,6 +143,13 @@ const executeReturnRaw = async (
query
)) as ExecuteReturnRaw
// Should over-ride response header for
// debug on GET request to see entire log
// rendering on browser.
if (isDebugOn(query)) {
httpHeaders['content-type'] = 'text/plain'
}
req.res?.set(httpHeaders)
if (result instanceof Buffer) {

View File

@@ -4,6 +4,7 @@ export * from './file'
export * from './generateAccessToken'
export * from './generateAuthCode'
export * from './generateRefreshToken'
export * from './isDebugOn'
export * from './getCertificates'
export * from './getDesktopFields'
export * from './parseLogToArray'

View File

@@ -0,0 +1,8 @@
import { ExecutionVars } from '../controllers/internal'
export const isDebugOn = (vars: ExecutionVars) => {
const debugValue =
typeof vars._debug === 'string' ? parseInt(vars._debug) : vars._debug
return !!(debugValue && debugValue >= 131)
}