Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwriting Fields in iRule #49

Open
davidpean opened this issue Feb 23, 2017 · 5 comments
Open

Overwriting Fields in iRule #49

davidpean opened this issue Feb 23, 2017 · 5 comments

Comments

@davidpean
Copy link

I am trying to verify that a URI rewrite is occuring -- Is it expected that you are unable to overwrite a field that you already set in the test with an iRule? For example:

iRule:

rule simple {

  when HTTP_REQUEST {
    HTTP::uri "/foobar"
  }

}

Test:

it "rewrite example" {
  event HTTP_REQUEST
  on HTTP::uri return "/foo"
  verify "URI is rewritten to" "/foobar" eq {HTTP::uri}
  run resources/simple_irule.tcl simple
}

in the debug, it looks like the value is getting set

debug HTTP::uri set: /foobar

However, when the verify executes it goes back to what was set in the on

info Returning value '/foo' for procedure call 'HTTP::uri'

error Verification 'URI is rewritten to' failed - expression: {/foobar} eq {/foo}

I know there is an issue trying to overwrite when using before statements, but wasn't sure if it was possible in the actual iRule. Any help would be much appreciated!

@landro
Copy link
Owner

landro commented Mar 23, 2017

Why would you try to mock out the uri when your're actually hardcoding it? That doesn't make any sense to me. Could you please elaborate on the use case for this?

@ernst-at-tv2
Copy link

One use-case that I have is that if a certain HTTP::uri is given we want to rewrite the uri to another value

@ernst-at-tv2
Copy link

ernst-at-tv2 commented Feb 21, 2019

@landro hope that this can help elaborate on why it would be a useful feature 🙂

irule.tcl

rule simple {
    when HTTP_REQUEST {
        if {[class match [getfield [HTTP::host] ":" 1][HTTP::uri] equals dg_redirect_map]} {
            set redirect_url [class match -value -- [getfield [HTTP::host] ":" 1][HTTP::uri] equals dg_redirect_map]
            HTTP::uri $redirect_url
            pool pool_traefik
        }
    }
}

test.tcl

package require -exact testcl 1.0.13
namespace import ::testcl::*

it "should rewrite HTTP::uri when matching key of datagroup" {
    class configure dg_redirect_map {
        "sport.blargh.com/video" "/section/video"
    }

    event HTTP_REQUEST
    on HTTP::host return "sport.blargh.com:80"
    on HTTP::uri return "/video"
    on pool pool_traefik return ""
    verify "the URI should be rewritten" "/section/video" eq {HTTP::uri}
    run irule.tcl simple
}

@landro
Copy link
Owner

landro commented Feb 26, 2019

Thanks for providing this example @ernst-at-tv2 !

@ernst-at-tv2
Copy link

figured out that I can actually test this if I do HTTP::uri "/video" in the test.tcl file, i.e. if I remove the on and return

I'm a bit puzzled as to what the difference between doing it like this is? I've hit another snag where I'm testing HTTP::path and that only works when I set HTTP::uri "/video" it won't work with on HTTP::uri return "/video" which wrongly returns / instead of /video

It might be a separate issue, just wanted to mention it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants