Forum Discussion
Packeteer_69831
Dec 06, 2010Nimbostratus
I've had my first attempt at writing the iRule for this and this is what I've come up with so far. Not sure if it's CMP compliant but it's parsing on 6400 running 10.2.0 HF2.
class uri_prepend_dgl {
"/prependabc" { "/prependxyz" }
}
class uri_replace_dgl {
{
"/123" { "/789" }
"/abc" { "/xyz" }
}
}
when HTTP_REQUEST {
log local0. "Original URI is: [HTTP::uri]"
set external_uri [HTTP::uri]
log local0. "External URI is: $external_uri"
if { [class match [HTTP::uri] equals "uri_replace_dgl"] } {
log "We're in the replace if statement"
set internal_uri [class search -value uri_replace_dgl eq [string tolower [HTTP::uri]]]
log local0. "Internal URI is: $internal_uri"
set HTTP::uri $internal_uri
} elseif { [class match [HTTP::uri] starts_with "uri_prepend_dgl"] } {
log local0. "We're in the prepend if statement"
set prepend_uri [class search -value uri_prepend_dgl starts_with [string tolower [HTTP::uri]]]
log local0. "Prepend URI is: $prepend_uri"
HTTP::uri "$prepend_uri[HTTP::uri]"
log local0. "Internal URI is: $prepend_uri[HTTP::uri]"
return
} else {
log local0. "We're in the do nothing part of the iRule"
log local0. "Passed URI is: [HTTP::uri]"
}
}
There's lots of logging so I can see what's happening in the ltm log whilst I run my curl commands.
It's sort of doing what I expect, however the prepend section isn't quite right. I can't work out how to preserve anything after the interesting part of the URI. For example, if I sent the URI "/prependabc" then the resulting URI is "/prependabc/prependxyz". However if the URI I send is "/prependabc123" my expectation is to get "/prependxyz/prependabc123" however this isn't the case. I can see why, but I can't work out in iRule lingo how to add the logic I'm after. I could just have a seperate statement for each prepend, however I'd like to recycle a function with a DGL rather than statically code this for each and every prepend.
I'll keep trying to work it out and then post for help in the main iRule thread.