1

I am having difficulty adding the method PATCH to MockServer.

I use the curl request below and the expectation is created properly.

While testing I receive the following error.

Method PATCH is not allowed by Access-Control-Allow-Methods in preflight response.

I am using the docker container and I am starting the container with the following command.

docker run -p 1080:1080 jamesdbloom/mockserver /opt/mockserver/run_mockserver.sh -logLevel INFO -serverPort 1080 -genericJVMOptions '-Dmockserver.enableCORSForAllResponses=false'

I have also tried

docker run -p 1080:1080 jamesdbloom/mockserver /opt/mockserver/run_mockserver.sh -logLevel INFO -serverPort 1080 -genericJVMOptions '-Dmockserver.enableCORSForAllResponses=true

curl -v -X PUT "http://localhost:1080/expectation" -d '{
    "httpRequest": {
      "method": "PATCH",
      "path": "/settings",
      "headers": {
          "Host": [".*"],
          "Connection": ["keep-alive"],
          "Origin": [".*"],
          "User-Agent": [".*"],
          "Access-Control-Request-Method": ["PATCH"],
          "access-control-request-headers": ["access-control-allow-origin,content-type"],
          "Accept.*": [".*"],
          "content-length": [".*"]
      },
      "body": {
          "type": "PARAMETERS",
          "parameters":                 
            {
              "email": ["user@example.com"],
              "name": ["User Name"],
              "password": ["supersecret"],
              "password_confirmation": ["supersecret"],
              "username": ["emanresu"]
          }
      }
    },
    "httpResponse": {
        "statusCode": 200,
        "headers": {
          "Content-Type": ["application/json"],
          "Server": ["nginx/1.13.12"],
          "Access-Control-Allow-Origin": ["*"],
          "Access-Control-Allow-Methods" : ["GET, HEAD, OPTIONS, POST, PUT, PATCH"],
          "Access-Control-Allow-Headers" : ["Access-Control-Allow-Origin, Authorization, Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Allow-Methods, Access-Control-Request-Method, Access-Control-Request-Headers"],
          "Access-Control-Expose-Headers": ["Access-Control-Allow-Origin, Authorization, Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Allow-Methods, Access-Control-Request-Method, Access-Control-Request-Headers"],
          "Access-Control-Max-Age": ["300"],
          "connection": ["close"]
        },
        "body": "{\"status\":\"success\"}"
    }
}'
whoacowboy
  • 6,982
  • 6
  • 44
  • 78
  • The error cited in the question is for the response from an OPTIONS request. So to test with curl, you need to make curl send an OPTIONS request first. So you need to ensure your server is sending the right headers in responses to OPTIONS requests — not just in responses to PATCH requests. – sideshowbarker Oct 04 '18 at 22:34
  • Your comment was kind of cryptic to me until I read your answer here https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe/43881141#43881141 which was vary enlightening. Thank you. – whoacowboy Oct 04 '18 at 23:47

0 Answers0