Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Header correlation using Reg Expressions

jesantos
jesantos Posts: 12

I need to send response based on the incoming request header, response will be different based on the first letter of the header value

I tried correlating headers in my responder and used values as: A*, B* and C* but I found that the only Regular expression allowed is for any header "[*]", seems I cannot use my own, is there a way I can correlate the header as needed?

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    You probably need to use the "Custom" correlation option. There are examples in the docs, including a regular expression example. The incoming request headers are available using context.get(CorrelationScriptingHookConstants.HEADERS) which returns a Map. So, your code would contain something like this (Groovy):

    Map<String, String> headers = context.get(CorrelationScriptingHookConstants.HEADERS)
    String myHeaderValue = headers.get("headerName")
    return myHeaderValue.matches("A.*")
    
  • jesantos
    jesantos Posts: 12

    I see I forgot replying back to this, thanks benken_parasoft!, that worked like a charm, I just have not tried custom correlations before, I see we can correlate anything here, since it is code based