Forum Discussion

karamelo25_9966's avatar
karamelo25_9966
Icon for Nimbostratus rankNimbostratus
Sep 08, 2009

Converts any special characters to hex encoding

Hi,

 

 

I need to covert any special characters to hex encoding to implement a irule (it should be equivalent to "Escape" Internal RewriteMap Function in Apache mod_rewrite).

 

 

Thanks

8 Replies

  • There is a command that can change string to hex

     

     

     

    binary scan $string h* pkt_in_hex

     

    log local0. "String in hex is: $pkt_in_hex"

     

     

  • But I need to convert only special characters of a string to hex encoding. Do you know how I could do it? Thanks
  • I am not sure where I follow? Do you need to convert them in general or do you need to convert them problematically in an iRule?

     

     

  • I have to make a irule where the value of a query parameter can contain some special character and it is necessary to convert these characters into hex.

     

  • Can you post and example of the full string with the querry. Also when it's converted where are you planning to use it?

     

     

    CB

     

  • I have to translate the following rewrite (apache) to irule:

     

     

    RewriteMap escape int:escape

     

    RewriteRule ^vegetables/(.*) vegetables.php?$1&HTTP_USER_AGENT=${escape:%{HTTP:User-Agent}}

     

     

    The problem is that I don't know how translate the escape function.

     

  • I'd guess that's doing URL encoding--not base64 encoding. You could use [URI::encode [HTTP::header User-Agent]] to URL encode the User-Agent header value.

     

     

    Aaron
  • All of the references I could find online for the Apache mod_rewrite escape functionality indicates they use URL (aka percent) encoding. The regex there doesn't quite make sense though as it's only going to match a URI starting with vegetables. A relative URI must start with a forward slash and an absolute URI must start with the protocol.

     

     

    As CB suggests, can you provide some sample requests and the rewritten result?

     

     

    Aaron