diff --git a/examples/example_irule_call.tcl b/examples/example_irule_call.tcl new file mode 100644 index 0000000..cf7023a --- /dev/null +++ b/examples/example_irule_call.tcl @@ -0,0 +1,15 @@ +package require -exact testcl 1.0.7 +namespace import ::testcl::* + +# Comment in to enable logging +#log::lvSuppressLE info 0 + +it "should redirect to the same url but using https" { + event HTTP_REQUEST + on HTTP::uri return "/bar" + on HTTP::host return "www.foo.com" + endstate HTTP::redirect https://www.foo.com/bar + run irules/call_irule.tcl call +} + +stats \ No newline at end of file diff --git a/irules/call_irule.tcl b/irules/call_irule.tcl new file mode 100644 index 0000000..bd31f1d --- /dev/null +++ b/irules/call_irule.tcl @@ -0,0 +1,18 @@ +rule call { + + proc Redirect {url} { + + HTTP::redirect $url + + } + + when HTTP_REQUEST { + + set lowerUri [string tolower [HTTP::uri]] + set lowerHost [string tolower [HTTP::host]] + + call Redirect https://$lowerHost$lowerUri + + } + +} \ No newline at end of file diff --git a/src/onirule.tcl b/src/onirule.tcl index 257dab6..af67315 100644 --- a/src/onirule.tcl +++ b/src/onirule.tcl @@ -161,3 +161,7 @@ proc ::testcl::run {irule rulename} { } testcl::assertStringEquals "rule $rulename" $result } + +proc ::testcl::call args { + return [eval $args] +}