feat(curl): configuration setting to pass additional options to curl command for "Try it out" (#6288)

Allows `requestInterceptor` to add options to the curl command.
For example:

```js
requestInterceptor: function (request) {
  if (request.method === 'GET') {
    request.curlOptions = ['-g']
    request.url = request.url
      .replace('%5B', '[')
      .replace('%5D', ']')
      .replace('%2C', ',');
  }
  return request;
}
```
This commit is contained in:
Adam David
2020-09-22 11:14:51 -07:00
committed by GitHub
parent 95fd3e71ab
commit cbe99c8c1a
3 changed files with 32 additions and 0 deletions

View File

@@ -364,4 +364,30 @@ describe("curlify", function () {
expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"RETURN \\$x + \\$y\"")
})
it("should include curlOptions from the request in the curl command", function () {
let req = {
url: "http://example.com",
method: "GET",
headers: { "X-DOLLAR": "token/123$" },
curlOptions: ["-g"]
}
let curlified = curl(Im.fromJS(req))
expect(curlified).toEqual("curl -g -X GET \"http://example.com\" -H \"X-DOLLAR: token/123\\$\"")
})
it("should include multiple curlOptions from the request in the curl command", function () {
let req = {
url: "http://example.com",
method: "GET",
headers: { "X-DOLLAR": "token/123$" },
curlOptions: ["-g", "--limit-rate 20k"]
}
let curlified = curl(Im.fromJS(req))
expect(curlified).toEqual("curl -g --limit-rate 20k -X GET \"http://example.com\" -H \"X-DOLLAR: token/123\\$\"")
})
})