fix middleware encoding