AngelaE / ts-mountebank

Mountebank client for TS / node
15 stars 5 forks source link

Allow setting the response mode #22

Closed TomLingham closed 1 year ago

TomLingham commented 1 year ago

HTTP Responses in Mountebank allow the configuration of "text" or "binary" bodies via the _mode option. This is required to allow bodies to respond with a binary body (which can be specified by passing a response body encoded as base64). More information can be found on the Mountebank HTTP protocols page.

This PR adds the ability to set the _mode value for a response in a backwards compatible way (despite "text" being the default value, it doesn't set it unless it's explicitly set by the consumer).

This doesn't add any additional QOL features for binary responses like base64 encoding a Buffer or UintNArray via a withBinaryBody method. More than happy to add that if you believe it is in the scope of this library to handle considering it does already have a similar QOL feature in the withJSONBody method.

(also, have only added a unit test — it didn't seem to fit into the current integration test suite but happy to craft something for that also)

AngelaE commented 1 year ago

@TomLingham This looks good and does not need an integration test. Could you make the minor change @maysam-tayyeb suggested? I will aim to merge and release this week.

TomLingham commented 1 year ago

Thanks, @AngelaE! I've updated this PR to include @maysam-tayyeb's feedback (thank you for merging the other PR, btw).

Thanks again, no rush on the release — we can wait. I appreciate the response 🙂