Skip to content

Scripting persist state between onRequest and onResponse #611

@edba

Description

@edba

In scripting it would be nice to be able to persist state between a request and its response, maybe via the context object or something similar. For example for holding on to the original requests url something like this could work:

function onRequest(context, url, request) {
  context.originalURL = url;
  request.schema = 'http';
  request.host = 'localhost';
  request.port = 8080;
  return request;
}


function onResponse(context, url, request, response) {
  // at this point `url` will be the updated one "localhost"
  // but context.originalURL would have the value of the original one.
  console.log(context.originalURL)
  return response;
}

this is a really simple example, but it would be useful to be able to reference state in onResponse that was derived inside onRequest

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request✅ DoneTicket is addressed and fixed.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions