Removed duplication in middleware

Removed the same code like https://github.com/pdfkit/pdfkit/blob/master/lib/pdfkit/middleware.rb#L25