Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Is there any string function that can calculate how many characters in a data variable in irule?

danielc
Cirrus
Cirrus

Hello,

For example I would like to know how many characters in [HTTP:uri] , is it possible to do so?

Thanks

 

4 REPLIES 4

Ichnafi
Cirrostratus
Cirrostratus

Hi,

give this a try:

string length [HTTP::uri]

Hello,

I have given it a try but faced problem:

when HTTP_REQUEST {

set thisuri [HTTP::uri]

...

}

 

when HTTP_RESPONSE {

if { [HTTP::status] == 404 } {


if { [ string length $thisuri ] > 2 } {

HTTP::respond 404 content "
<html>
<head>
<title>Not Found</title>
</head>
<body>
<h2>Not Found</h2>
This page is not found.<br>
<p></p>
</body>
</html>


} else {

HTTP::respond 404 content "
<html>
<head>
<title>Not Found</title>
</head>
<body>
<h2>Not Found</h2>
This website is not found.<br>

<p></p>
</body>
</html>
"
}
}

 

But I faced this error

01070151:3: Rule [/Common/check_url] error: /Common/check_url:63: error: [parse error: missing "]["

line 63 is  HTTP::respond 404 content "

line 61 is  if { [string length $thisuri] > 2 } then {

Any idea? Thanks

Ichnafi
Cirrostratus
Cirrostratus

You are missing a quotation mark (") after </html> in the if clause.
May i suggest, that you use a "real" editor to write iRules.
Maybe try VScode with the extension "F5 Network iRules". With propper syntax highlighting errors like this are more easy to spot.

 

Thanks for your suggestion, I am using it, It is too difficult to do the irule programming directly on bigip.