NR-610 : Complete the security gateway

Refactoring for a more general support for gateways (not
only specific for HTTP)