dreamhead / moco

Easy Setup Stub Server
MIT License
4.36k stars 1.08k forks source link

Expectations vs. URI encoding? #282

Closed kerrykimbrough closed 4 years ago

kerrykimbrough commented 4 years ago

Certain characters in a request URI must be percent-encoded. For example, a space char must be encoded as "%20". My question is: how must I handle this when I'm configuring the expectations for the Moco server? This question ought to be answered in the documentation, but I couldn't find it.

For example, consider a request of the form PATCH http://myhost.com/user/{id}?name={name} where id is "A|B" and name is "Mr. Peabody".

What is the correct way to configure expectations for this request? If Moco handles encoding automatically, it might be like this:

{
    "request": {
        "uri": "/user/A|B",
        "method": "patch",
        "queries": {
            "name": "Mr. Peabody"
        }
    },
    ...
}

Or if I have to compute the encoding manually, it might be like this:

{
    "request": {
        "uri": "/user/A%7CB",
        "method": "patch",
        "queries": {
            "name": "Mr.%20Peabody"
        }
    },
    ...
}
dreamhead commented 4 years ago

Moco provides only raw text in its configuration, so you have to encode them by yourself.

kerrykimbrough commented 4 years ago

Actually, I've been able to verify that manual encoding is NOT needed. The first example above works fine. Apparently, the server request handler that Moco uses does this automatically.