vADC Forum

Reply
Occasional Contributor
Posts: 15
Registered: ‎11-30-2012
Accepted Solution

How to Send html file file extra

How to send a HTML file that is stored on the extra folder on STM from the user url request?

Brocadian
Posts: 232
Registered: ‎11-29-2012

Re: How to Send html file file extra

Richard,

    You can use the resource.get() function to read the contents of the file then send it to the user with http.setResponseBody() function.

resource.get( filename )

Returns the contents of a named file stored in the ZEUSHOME/zxtm/conf/extra/ directory. If the file doesn't exist, then an empty string is returned. Note that subdirectories of conf/extra are not supported.
Resources are pre-loaded into memory, so this call does not cause the file to be reloaded.

# Read the contents of the 'info' file and add them
# as a new header.
http.addheader( "X-Info", resource.get( "info" ));

http.setResponseBody( body, [transfer-encoding] )

Sets the response body for this HTTP response to the supplied string, replacing any response body already present.
This also updates the 'Content-Length' header in the response to the length of the new body data. In addition the 'Content-Encoding' header is removed as we only ever set body data which is not encoded or compressed. If the server is still sending the original response body when this function is called, the connection to the server will be harmlessly dropped.
The optional 'transfer-encoding' parameter indicates the encoding of the body data (for example, 'chunked').

$body = http.getResponseBody( 0 );
$body = string.regexsub( $body, "Buy", "Sell", "g" );
http.setResponseBody( $body );
Occasional Contributor
Posts: 15
Registered: ‎11-30-2012

Re: How to Send html file file extra

##

# Function Looks for /akamai-sureroute-test-object.html Test Page

#

# Date: 2012.12.17

# By: rhp

# Usage: In other Traffic Scripts add the following line:

# import SureRoute_TestPage;

#

##

if (string.wildmatch(http.getRequest(),"*/akamai-sureroute-test-object.html*")){

   log.info("Path Match is Test");

  

   $file = "sureroute-test-object.html" ;

   if( resource.exists( $file ) ) {

      $html = "";

      $body = resource.getLines( $file );                

      foreach ( $line in $body ) {

         $html .= $line;

      }

      #$body = resource.get( "$file" );                

      log.info("Sure Route Test File found.");

      http.sendResponse(

      "200",

      "text/html", $html,

      "");

      connection.discard();

      break;

   

   } else {

      log.info("Sure Route Test File not found.");

   }

}

Contributor
Posts: 74
Registered: ‎10-03-2011

Re: How to Send html file file extra

Hi Richard,

Just a couple of recommendations....

1. You don't need to stitch the file together line by line. You can just use resource.get() to load the whole file at once.

2. http.sendResponse() terminates processing and sends the data to the client, therfore you don't need to include the connection.discard() or the break.

Cheers,

Mark

Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.

Click to Register
Download FREE NVMe eBook