Port condition fix

The port condition test was based on the request being handled and not the port configured in the rule. Additionally added tests and cleaned up some code.