I have written a number of functions in fiddler as a static function that gets called to parse the URL line that Fiddler received. We use this as an external API emulator for testing. While everything works when calling our code from within the OnPeekAtResponseHeaders() or OnBeforeResponse(), the response code cannot be changed.
Within either of these functions (have called my function from both with no success) we can call:
static function OnBeforeResponse(oSession: Session) {
oSession = Emulator(oSession); // Call our code
...
}
or
static function OnPeekAtResponseHeaders(oSession: Session) {
oSession = Emulator(oSession);
...
}
In our code, we basically look at the URI called:
if (oSession.uriContains("/rest/SomeAPICall") ) {
// Decide what text file on the OS to return based on parameters or RequestBody contents
...
} else if (oSession.uriContains("/rest/SomeAPICall2") ) {
// Decide what text file on the OS to return based on parameters or RequestBody contents
...
} else if (oSession.uriContains("/rest/SomeAPICall3") ) {
// Decide what text file on the OS to return based on parameters or RequestBody contents
...
}
The return data is set using the OS
var ResponseFile = new ActiveXObject("Scripting.FileSystemObject");
if (ResponseFile.FileExists(ReturnFileName)) {
oSession["x-replywithfile"] = ReturnFileName;
} else {
// Error message returned as the ReturnBody was not populated and Response File not found
oSession.utilSetResponseBody(ErrorMessage);
}
Based on the decisions on the file, we set a variable (HttpStatus) that we try to set in the responseCode
oSession.responseCode = HttpStatus;
oSession.oResponse.headers.HTTPResponseCode = HttpStatus;
oSession.oResponse.headers.HTTPResponseStatus = HttpStatus + ' ' + HttpStatusText;
And then ultimately return the oSession to the caller function:
return oSession;
While the results of our text files are returned in the response, I cannot get the status code to change from 200. I must be doing something wrong but cannot find what it is.