[bug 883149] Added custom middleware support

ref: https://bugzilla.mozilla.org/show_bug.cgi?id=883149