Section - Rewrite Response Body (any content)
Section - Rewrite Response Body (any content)

In addition to rewriting the response body for HTML, where the HTML parser of Airlock Gateway lets you define rewrite rules for different semantic parts of HTML, such as URLs and JavaScript, you can configure Gateway to generally rewrite the body of HTTP responses.

To specify what bodies shall be rewritten, each rule is accompanied by a Content type field. If a HTTP request or response contains a Content-Type header that matches the regular expression in that field, the rule will be applied.

Note: The rewrite rules will be executed in sequence if the content type field is identical – the relative order of rewrite rules with the same regular expression in the content type field is essential. If the content type field differs, but matches in both cases, the order is undefined.

Content type

A response from the back-end server is rewritten only if the response header «Content-Type» matches this regular expression.

Content Pattern

This regular expression pattern defines the content to rewrite. Text parts reusing in Replace with have to marked with parentheses "( )".

The type specifier ?<URL> right after the opening parenthesis indicates a URL. If URL encryption is enabled, this URL will also be encrypted.

For each pattern the Ignore Case check-box defines if the pattern should be applied case sensitive or not.

Replace with

This is the target string which will replace the string matched by Content Pattern. Substrings marked for reuse in Content Pattern field can be inserted using $1, $2, …

Examples

Purpose
Rewrite URLs in CSS import statements in HTML and CSS documents (type A)
Content Type
^(?:text|application)/(?:html|xhtml|css)
Content Pattern
(@import[\h\v]*["'])(?<URL>[^"']+)(["'])
Replace with
$1$2$3
Example
HTML snippet from back-end: <style> @import "/styles/mystyle1.css"; @import'/styles/mystyle2.css'; <style> After rewriting (URL encryption enabled): <style> @import "/ue/$xp1/babp8tnonc73G9p7No9li1UQQcNMV9c3i_l0mxNDOCAJ7oId$/p/p/p/p/p/p"; @import'/ue/$xp1/F5KkmMJ!lPO_3kTwlwP9myON3rJTzIrNinPR_DNpVXWwJS3e$/p/p/p/p/p/p'; </style>
 
 
Purpose
Rewrite URLs in CSS import statements in HTML and CSS documents (type B)
Content Type
^(?:text|application)/(?:html|xhtml|css)
Content Pattern
(@import[\h\v]+url\([\h\v]*["']?)(?<URL>[^"')]+)(["')])
Replace with
$1$2$3
Example
CSS snippet back-end: @import url("mystyle.css"); p.otherSyles { color: green } After rewriting (URL encryption enabled): @import url("/ue/$xp1/3YYQVMpExKtQZNKKqJjDNAAadQfHArO8GSb9Xfx1RDVqDi6s$/p/p/p/p/p/p"); p.otherSyles { color: green }

Further information and links