Showing results for 
Search instead for 
Did you mean: 

HowTo: Query an external datasource using HTTP

A TrafficScript rule can ask Stingray to query an external datasource using a variety of methods - HTTP, an authentication protocol such as LDAP, via a Java Extension or using a simple TCP socket.


Querying a datasource using HTTP


For example, Stingray may wish to validate a request's credentials by querying an external database via a web gateway. In this sample rule, Stingray extracts and decodes the username and password given in a Basic authentication header. Stingray then sends the username and password to a script on a nearby websserver which contains all the logic to check the credentials. The webserver returns an 'OK' message if the credentials check out.


# This returns the header value 'Basic 3AD35sd5oPkS4nHha2'   
$auth = http.getHeader( "Authorization" );   
# Extract and decode the encoded username and password   
$enc = string.skip( $h, 6 );   
$userpasswd = string.base64decode( $enc );   
# Parse the usernameSmiley Tongueassword string   
string.regexmatch( $userpassword, "([^:]*)Smiley Sad.*)" );   
$user = $1; $password = $2;   
# Query the 'auth.cgi' script on   
$body = http.request.get( "".$user."&password=".$password );   
if( string.contains( $body, "OK" ) ) {     
    # the credentials check out OK      
} else {  
   # the credentials are bogus!  


A more complete implementation of this would have to send the '401 Authenticate' response and 'WWW-Authenticate' header, and MAY use 'data.set()' and 'data.get()' to cache the responses from the remote authentication server to improve performance.


Read more


Version history
Revision #:
1 of 1
Last update:
‎02-24-2013 06:49:AM
Updated by:
Labels (1)