cancel
Showing results for 
Search instead for 
Did you mean: 

Set header with Generic Streaming Protocol?

SOLVED
felixdpg
Occasional Contributor

Set header with Generic Streaming Protocol?

Hi All:

I have a Generic Streaming virtual server in order to demultiplex the traffic incoming for an especific port. The question is:

How I can modify the header when the request are http? .I know that I could add a parmeter such as :

http.setHeader("X-Forwarded-For", request.getRemoteIP());

1 ACCEPTED SOLUTION

Accepted Solutions
markbod
Contributor

Re: Set header with Generic Streaming Protocol?

Hi Felix,

Unfortunately you can't use the HTTP class of functions with non-http protocols. You will need to use request.get()/request.set() instead. Something like this might work...


$line = request.get( request.getLength() );


if ( string.regexmatch($line, "(.*?HTTP/1.*?)\r\n\r\n(.*)") ) {


   request.set($1 . "\r\n" . "X-Forwarded-For: " .


     request.getRemoteIP() . "\r\n\r\n" . $2 );


}



As this is not HTTP, you will see you have an option to run the rule once or every. You will need to set that to every if you want to execute the rule on every request, rather than just on initial connection.


You may also find this blog post useful: Stingray Technical Blog: October 2006


Cheers,

Mark


View solution in original post

4 REPLIES 4
markbod
Contributor

Re: Set header with Generic Streaming Protocol?

Hi Felix,

Unfortunately you can't use the HTTP class of functions with non-http protocols. You will need to use request.get()/request.set() instead. Something like this might work...


$line = request.get( request.getLength() );


if ( string.regexmatch($line, "(.*?HTTP/1.*?)\r\n\r\n(.*)") ) {


   request.set($1 . "\r\n" . "X-Forwarded-For: " .


     request.getRemoteIP() . "\r\n\r\n" . $2 );


}



As this is not HTTP, you will see you have an option to run the rule once or every. You will need to set that to every if you want to execute the rule on every request, rather than just on initial connection.


You may also find this blog post useful: Stingray Technical Blog: October 2006


Cheers,

Mark


felixdpg
Occasional Contributor

Re: Set header with Generic Streaming Protocol?

Ok, thanks so much Mark, I will test the script and put the result here.

Regards

Felix

felixdpg
Occasional Contributor

Re: Set header with Generic Streaming Protocol?

Mark:

This script work perfectly but not for all request. The problem is that appear the origin IP in only a few numbers of request.

( string.regexmatch($line, "(.*?HTTP/1.*?)\r\n\r\n(.*)") )  ????


What about set header in non-http connections?.


Regards and thanks so much for the reply.


Felix

felixdpg
Occasional Contributor

Re: Set header with Generic Streaming Protocol?

Hi Mark:

Finally this is the script with a little modification.

$data = request.get()

$count = 500

while( $data == "" && $count-- > 0 )

   connection.sleep( 10 );

   $data = request.get()

}

if ( string.regexmatch($data, "(.*?HTTP/1.*?)\r\n\r\n(.*)") )

   request.set($1 . "\r\n" . "X-Forwarded-For: " .  

    request.getRemoteIP() . "\r\n\r\n" . $2 )

}


Now I can catch all of the origin IP but only fot HTTP and HTTPS (with SSL Offload).

Thanks so much for your reply and for the script.


Cheers


Felix