Port Facebook middleware from Katana.