On Fri, Nov 17, 2006 at 11:39:56AM +0000, sebb wrote:
> The Regex Post-Processor can be applied to Headers, but this feature
> has not yet been applied to the Response Assertion, sorry.
> 
> It's a useful feature - just no-one has got round to implementing it yet.
> 
> I've added a Bugzilla enhancement request so it does not get forgotten.
> 
> As a work-round, you could use the BeanShell Assertion to get access
> to the Headers.

Even with my incredibly weak Java skills I was able to get something
simple to work. Does this look sane?

import java.util.regex.Pattern;
import java.util.regex.Matcher;

if (ResponseCode.equals("200")) {
    // NOTE: the ResponseHeaders are a String with embedded newlines. 
    // I wasn't able to use the ^ or $ anchors in my regex. If this
    // were required perhaps the string could be split into an array of
    // strings?

    String p = "X-Cache: HIT";
    Pattern pattern = Pattern.compile(p);
    Matcher matcher = pattern.matcher(ResponseHeaders);
    if (!matcher.find()) {
        Failure = true ;
        FailureMessage = "The " + p + 
                         " header was not present in response headers.\n" +
                         ResponseHeaders;
    } 
} else {
    Failure = true;
    FailureMessage = "Error: HTTP Response code " + ResponseCode;
}

Thanks! 

-- 
Steve Feehan

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to