Contribute Open Script

Payload inspection sample 2: Do response payload match and replacement when status code match 200

by lix ‎04-01-2014 04:46 PM - edited ‎04-02-2014 03:48 PM (1,297 Views)

Tested with Brocade ServerIron ADX : Yes

Description :

if response status code matches "200", ADX will inspect the response payload content. When any words in the payload matches patterns 'computer networks 1', 'computer networks 2', 'computer networks 3', PAYLOAD_INSPECT_MATCHED event will be triggered, and matched patterns will be replaced by the target words.

 

 

use OS_SLB;
use OS_HTTP_RESPONSE;
use OS_PAYLOAD_INSPECT;

sub HTTP_RESPONSE {
    my $code = OS_HTTP_RESPONSE::code;
    print "Response status code: $code\n";
    if ( $code == 200) {
        OS_PAYLOAD_INSPECT::match(
                'computer networks 1',
                'computer networks 2',
                'computer networks 3'
       );
    }
}


sub PAYLOAD_INSPECT_MATCHED {
    my $matString = OS_PAYLOAD_INSPECT::matched_str();
    my $matIndex = OS_PAYLOAD_INSPECT::matched_idx();


    print "\nMatched string ($matString) & Index is: $matIndex\n";

 

    OS_PAYLOAD_INSPECT::matched_replace(
        0, ' =============== REPLACED SMALL LENGTH STRING TO LARGE LENGTH STRING TO TEST - OPEN SCRIPT PAYLOAD INSPECT API =============== ',
        'free', ' @@@ FREE IS REPLACED AS LICENSE @@@ ',
        '', ' --- PAYLOAD INSPECT --- '
   );
}

Contributors