bbyars / mountebank

Over the wire test doubles
http://www.mbtest.org
MIT License
2k stars 262 forks source link

[Feature Request] Allow mountebank to send back statusMesage #746

Open clickthisnick opened 9 months ago

clickthisnick commented 9 months ago

Expected behaviour

I was hoping I could add a statusMessage in the response body:

    "responses": [
        {
            "headers": {
                "Content-Type": "application/json"
            },
            "statusMessage": "foobar",
            "is": {
                "body": {
                    "foo": "bar
                    },
....

Which in turn in mountebank would essentially do:

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, "STATUS MESSAGE", {'Content-Type': 'text/plain'});
    res.write('Hello World!');
    res.end();
}).listen(8080);

Actual behaviour

I have a service that I don't own and have no control over that uses the statusMessage (also called reason phrases) to communicate information that is critical to take action on.

An example is wget https://example.com in my scenario would return:

HTTP request sent, awaiting response... 503 up

503 is the statusCode

up is the statusMessage

I need to be able to mock this statusMessage with mountebank as the "up" message is necessary to do certain actions on.

Mountebank uses writeHead from node https://github.com/nodejs/node/blob/99f6084ef04dd868c7b894ca0fdbb5088773ca6c/lib/_http_server.js#L341-L365

Here: https://github.com/bbyars/mountebank/blob/09e2e4a31f696b5555e7a250b5a440816cea91bc/src/models/http/baseHttpServer.js#L143

Looking into the nodejs http code we can see statusMessage is an optional argument that defaults what we normally see as the message (but it is overridable).

Steps to reproduce

There's no current way to mock the statusMessage

Software versions used

OS         :
mountebank :
node.js    :
  (only if installed via npm)
Installation method :
  (npm, zip, tar, pkg, deb, rpm)

mountebank latest

Log contents in mb.log when running mb --loglevel debug

Log contents here

No logs as its not compatible with the code if I'm groking