3

I am trying to provide a MOCK service that takes a headerName and value from the query and returns it as a (dynamic) header with the response. I am using the following response definition:

"response" : {
  "status" : 200,
  "statusMessage": "OK",
  "headers" : {
    "Content-Type" : "application/json",
    "{{request.query.debugHeader}}" : "{{request.query.debugHeaderValue}}"
  },
  "jsonBody" : {
    "headerSent": "{{request.query.debugHeader}} {{request.query.debugHeaderValue}}"
  },
  "transformers": ["response-template"],
  "base64Body" : ""
}

The header value is correctly evaluated and put into the response template, however I can't get the header name to be taken from the request.

When sending a request:

http://localhost:8090/example?debugHeader=name&debugHeaderValue=value

The result headers I get back are:

HTTP/1.1 200 OK
Content-Type: application/json
{{request.query.debugHeader}}: value

However I want {{request.query.debugHeader}} to be replaced with the actual request parameter value ("name" in the example above).

Any ideas?

Thanks in advance Alex

A. Fuss
  • 31
  • 1
  • 3

2 Answers2

2

This is supported in WireMock.Net.

The request which you need to specify looks like this:

{
    "Guid": "90356dba-b36c-469a-a17e-669cd84f1f05",
    "Priority": 0,
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/trans",
                    "IgnoreCase": false
                }
            ]
        },
        "Methods": [
            "get"
        ]
    },
    "Response": {
        "StatusCode": 200,
        "BodyDestination": "SameAsSource",
        "Body": "{\"msg\": \"Hello world : {{request.path}}\" }",
        "UseTransformer": true,
        "Headers": {
            "Content-Type": "application/json",
            "Transformed-Postman-Token_{{request.path}}": "token is {{request.headers.Postman-Token}}"
        }
    }
}

This will add the transformed header Transformed-Postman-Token_{{request.path}} in the response.

Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121
0

Presently this type of variability is not part of the out-of-the-box WireMock application and would have to be custom added. In the WireMock documentation the section Extending WireMock and in particular the part on Transforming Responses.

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43