http-response

Use a script to modify the HTTP response. The value field is a regular expression to match the request URLs.

The incoming parameters are $request and $response:

  • $request.url<String>: Request URL
  • $request.method<String>:Request HTTP method

  • $response.status<Number>: Response HTTP status code

  • $response.headers<Object>: Response HTTP Headers
  • $response.body<String>: Response HTTP Body, decoded to string with UTF-8. Only exists when requires-body = true.

The script must invoke $done() with an object. The object may contain:

  • body<String>: Use the new body to overwrite the old one. Only works when requires-body = true.
  • headers<Object>: Use the new headers to overwrite all the old headers. Please note that some fields may not be modified, such as 'Content-Length'.
  • status<Number>: Use the new status code to overwrite the old one.

You may use $done(); to abort the request without returning anything. Or use $done({}); to keep the response untouched.

A simple example:

let headers = $response.headers;
headers['X-Modified-By'] = 'Surge';

$done({headers});

results matching ""

    No results matching ""