:thread: not able to add `host`in mock request
# help
p
🧵 not able to add `host`in mock request
I am running wiremock version 3.9.2
Copy code
{
  "request": {
    "scheme": "http",
    "url": "/other/thing",
    "method": "GET",
    "host": "<http://example.com|example.com>"
  },
  "scenarioName": "test",
  "response": {
    "status": 200,
    "jsonBody": {
      "body": "Hello, world!"
    },
    "headers": {
      "Content-Type": "application/json"
    }
  }
}
this is the mapping file
I am getting this error
Copy code
my_wiremock  | Exception in thread "main" com.github.tomakehurst.wiremock.standalone.MappingFileException: Error loading file /home/wiremock/./mappings/mock.json:
my_wiremock  | "<http://example.com|example.com>" is not a valid match operation
my_wiremock  |  at com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource.loadMappingsInto(JsonFileMappingsSource.java:126)
what am I missing here?
r
are you trying to match the host header? if so, you'll want
Copy code
"request": {
    "scheme": "http",
    "url": "/other/thing",
    "method": "GET",
    "headers": {
      "host": {
        "equalTo": "<http://example.com|example.com>"
      }
    }
  },
p
Can do that, but my question if you look at API doc it says you can mention
host
just like you mention
url
.
Hence I am not sure, if the doc is wrong or I am doing something wrong
r
that is very true. i had not seen that before. looks like the
string
type is inaccurate and would need to be an object. so,
Copy code
"request": {
    "scheme": "http",
    "url": "/other/thing",
    "method": "GET",
    "host": {
      "equalTo": "<http://example.com|example.com>"
    }
  },
p
yes, this works thanks for the help!
r
happy to help