initial support for swift middleware

WIP, waiting for possible comments