mountebank icon indicating copy to clipboard operation
mountebank copied to clipboard

Provide better support for binary in HTTP

Open bbyars opened this issue 10 years ago • 3 comments

Binary HTTP currently works on a whitelist of content-types, which is very counter to the general-purpose nature of most mountebank code. It completely fails when it should be binary but doesn't recognize the content type as such.

See https://groups.google.com/forum/#!topic/mountebank-discuss/ihlpRGhAVBw for a specific example.

bbyars avatar Oct 24 '15 03:10 bbyars

What is the symptom of this failure? I'm attempting to proxy to a webserver, and am getting some apparent mangling of response. For example, fetching a PDF, the original content (hexdump) is:

00000000  25 50 44 46 2d 31 2e 35  0d 25 e2 e3 cf d3 0d 0a  |%PDF-1.5.%......

but I'm getting back

00000000  25 50 44 46 2d 31 2e 35  0d 25 ef bf bd ef bf bd  |%PDF-1.5.%......
00000010  ef bf bd ef bf bd 0d 0a  36 35 30 20 30 20 6f 62  |........650 0 ob

ie: the input e2 e3 cf d3 is getting mangled to "ef bf bd ef bf bd ef bf bd ef bf bd" (four copies of "ef bf bd" - the UTF-8 replacement character)

lyricnz avatar May 24 '17 03:05 lyricnz

Nearly everything in mountebank is very general purpose, with the exception of HTTP binary support, especially during proxying. It is driven by very special case logic that examines the content-type and content-encoding headers. If one of those headers fits within a whitelist of known binary types, mountebank encodes the response as binary; otherwise it encodes it as text which results in mangling. PDFs aren't in the very small whitelist (see the isBinaryResponse function in httpProxy https://github.com/bbyars/mountebank/blob/master/src/models/http/httpProxy.js), but neither are a million other legitimate binary formats.

A simple short-term fix for your specific problem should be to patch that function to add the pdf content-type to the list. A longer term solution is needed, but not obvious to me at the moment...

On Tue, May 23, 2017 at 10:33 PM, Simon Roberts [email protected] wrote:

What is the symptom of this failure? I'm attempting to proxy to a webserver, and am getting some apparent mangling of response. For example, fetching a PDF, the original content (hexdump) is:

00000000 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a |%PDF-1.5.%......

but I'm getting back

00000000 25 50 44 46 2d 31 2e 35 0d 25 ef bf bd ef bf bd |%PDF-1.5.%...... 00000010 ef bf bd ef bf bd 0d 0a 36 35 30 20 30 20 6f 62 |........650 0 ob

ie: the input e2 e3 cf d3 is getting mangled to "ef bf bd ef bf bd ef bf bd ef bf bd" (four copies of "ef bf bd")

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bbyars/mountebank/issues/78#issuecomment-303608388, or mute the thread https://github.com/notifications/unsubscribe-auth/AAESv_GhrObk3vpWwrIOCiPBHukN7Uqmks5r86UHgaJpZM4GU8fH .

bbyars avatar May 24 '17 04:05 bbyars

Added several more MIME types for binary detection

bbyars avatar Feb 09 '20 21:02 bbyars