diff --git a/README.md b/README.md index 584a646dd..cb59c19ba 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ snippets/ #### source -*Required* +*Required* Type: `object` Name of [conversion target](https://github.com/Mashape/httpsnippet/wiki/Targets) @@ -87,7 +87,7 @@ var snippet = new HTTPSnippet({ #### target -*Required* +*Required* Type: `string` Name of [conversion target](https://github.com/Mashape/httpsnippet/wiki/Targets) @@ -119,7 +119,7 @@ console.log(snippet.convert('node', { #### target -*Required* +*Required* Type: `string` Name of [conversion target](https://github.com/Mashape/httpsnippet/wiki/Targets) @@ -153,6 +153,39 @@ console.log(snippet.convert('shell', 'curl', { console.log(snippet.convert('node', 'unirest')); ``` +### addTarget(target) +#### target + +*Required* +Type: `object` + +Representation of a [conversion target](https://github.com/Kong/httpsnippet/wiki/Creating-Targets). Can use this to use targets that are not officially supported. + +```js +const customLanguageTarget = require('httpsnippet-for-my-lang'); +HTTPSnippet.addTarget(customLanguageTarget); +``` + +### addTargetClient(target, client) +### target + +*Required* +Type: `string` + +Name of [conversion target](https://github.com/Mashape/httpsnippet/wiki/Targets) + +### client + +*Required* +Type: `object` + +Representation of a [conversion target client](https://github.com/Kong/httpsnippet/wiki/Creating-Targets). Can use this to use target clients that are not officially supported. + +```js +const customClient = require('httpsnippet-for-my-node-http-client'); +HTTPSnippet.addTargetClient('node', customClient); +``` + ## Documentation At the heart of this module is the [HAR Format](http://www.softwareishard.com/blog/har-12-spec/#request) as the HTTP request description format, please review some of the sample JSON HAR Request objects in [test fixtures](/test/fixtures/requests), or read the [HAR Docs](http://www.softwareishard.com/blog/har-12-spec/#request) for more details. diff --git a/package-lock.json b/package-lock.json index 311db968e..f56dc1d2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "httpsnippet", - "version": "1.19.1", + "version": "1.21.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -245,20 +245,20 @@ "dev": true }, "cliui": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", - "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", + "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", "dev": true, "requires": { - "string-width": "^2.1.1", - "strip-ansi": "^4.0.0", - "wrap-ansi": "^2.0.0" + "string-width": "^3.1.0", + "strip-ansi": "^5.2.0", + "wrap-ansi": "^5.1.0" }, "dependencies": { "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, "is-fullwidth-code-point": { @@ -268,22 +268,23 @@ "dev": true }, "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", "dev": true, "requires": { + "emoji-regex": "^7.0.1", "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" + "strip-ansi": "^5.1.0" } }, "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "dev": true, "requires": { - "ansi-regex": "^3.0.0" + "ansi-regex": "^4.1.0" } } } @@ -388,27 +389,6 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, - "cross-spawn": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", - "dev": true, - "requires": { - "nice-try": "^1.0.4", - "path-key": "^2.0.1", - "semver": "^5.5.0", - "shebang-command": "^1.2.0", - "which": "^1.2.9" - }, - "dependencies": { - "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", - "dev": true - } - } - }, "d": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", @@ -632,15 +612,6 @@ "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", "dev": true }, - "end-of-stream": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", - "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", - "dev": true, - "requires": { - "once": "^1.4.0" - } - }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -1060,21 +1031,6 @@ "through": "~2.3.1" } }, - "execa": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", - "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", - "dev": true, - "requires": { - "cross-spawn": "^6.0.0", - "get-stream": "^4.0.0", - "is-stream": "^1.1.0", - "npm-run-path": "^2.0.0", - "p-finally": "^1.0.0", - "signal-exit": "^3.0.0", - "strip-eof": "^1.0.0" - } - }, "exit-hook": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz", @@ -1287,15 +1243,6 @@ "integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=", "dev": true }, - "get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -1342,17 +1289,24 @@ "dev": true }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.7.6", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.6.tgz", + "integrity": "sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA==", "dev": true, "requires": { + "minimist": "^1.2.5", "neo-async": "^2.6.0", - "optimist": "^0.6.1", "source-map": "^0.6.1", - "uglify-js": "^3.1.4" + "uglify-js": "^3.1.4", + "wordwrap": "^1.0.0" }, "dependencies": { + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -1482,12 +1436,6 @@ "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==", "dev": true }, - "invert-kv": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", - "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", - "dev": true - }, "is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -1495,9 +1443,9 @@ "dev": true }, "is-buffer": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", - "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", + "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==", "dev": true }, "is-callable": { @@ -1571,12 +1519,6 @@ "integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==", "dev": true }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", - "dev": true - }, "is-symbol": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", @@ -1754,15 +1696,6 @@ "integrity": "sha1-OGchPo3Xm/Ho8jAMDPwe+xgsDfE=", "dev": true }, - "lcid": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", - "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", - "dev": true, - "requires": { - "invert-kv": "^2.0.0" - } - }, "lcov-parse": { "version": "0.0.10", "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-0.0.10.tgz", @@ -1813,9 +1746,9 @@ } }, "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", "dev": true }, "lodash.cond": { @@ -1880,31 +1813,11 @@ "yallist": "^2.1.2" } }, - "map-age-cleaner": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", - "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", - "dev": true, - "requires": { - "p-defer": "^1.0.0" - } - }, "map-stream": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.1.0.tgz", "integrity": "sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ=" }, - "mem": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", - "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", - "dev": true, - "requires": { - "map-age-cleaner": "^0.1.1", - "mimic-fn": "^2.0.0", - "p-is-promise": "^2.0.0" - } - }, "mime-db": { "version": "1.40.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", @@ -1918,12 +1831,6 @@ "mime-db": "1.40.0" } }, - "mimic-fn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", - "dev": true - }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -1962,9 +1869,9 @@ "integrity": "sha1-LISJPtZ24NmPsY+5piEv0bK5qBk=" }, "mocha": { - "version": "6.1.4", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-6.1.4.tgz", - "integrity": "sha512-PN8CIy4RXsIoxoFJzS4QNnCH4psUCPWc4/rPrst/ecSJJbLBkubMiyGCP2Kj/9YnWbotFqAoeXyXMucj7gwCFg==", + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-6.2.3.tgz", + "integrity": "sha512-0R/3FvjIGH3eEuG17ccFPk117XL2rWxatr81a57D+r/x2uTYZRbdZ4oVidEUMh2W2TJDa7MdAb12Lm2/qrKajg==", "dev": true, "requires": { "ansi-colors": "3.2.3", @@ -1979,7 +1886,7 @@ "js-yaml": "3.13.1", "log-symbols": "2.2.0", "minimatch": "3.0.4", - "mkdirp": "0.5.1", + "mkdirp": "0.5.4", "ms": "2.1.1", "node-environment-flags": "1.0.5", "object.assign": "4.1.0", @@ -1987,9 +1894,9 @@ "supports-color": "6.0.0", "which": "1.3.1", "wide-align": "1.1.3", - "yargs": "13.2.2", - "yargs-parser": "13.0.0", - "yargs-unparser": "1.5.0" + "yargs": "13.3.2", + "yargs-parser": "13.1.2", + "yargs-unparser": "1.6.0" }, "dependencies": { "debug": { @@ -2040,6 +1947,21 @@ "path-exists": "^3.0.0" } }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + }, + "mkdirp": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.4.tgz", + "integrity": "sha512-iG9AK/dJLtJ0XNgTuDbSyNS3zECqDlAhnQW4CsNxBG3LQJBbHmRX1egw39DmtOdCAqY+dKXV+sgPgilNWUKMVw==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", @@ -2047,9 +1969,9 @@ "dev": true }, "p-limit": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", - "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", "dev": true, "requires": { "p-try": "^2.0.0" @@ -2070,12 +1992,6 @@ "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "dev": true }, - "strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", - "dev": true - }, "supports-color": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.0.0.tgz", @@ -2116,12 +2032,6 @@ "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=", "dev": true }, - "nice-try": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", - "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", - "dev": true - }, "node-environment-flags": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.5.tgz", @@ -2133,9 +2043,9 @@ }, "dependencies": { "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "dev": true } } @@ -2149,15 +2059,6 @@ "abbrev": "1" } }, - "npm-run-path": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", - "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", - "dev": true, - "requires": { - "path-key": "^2.0.0" - } - }, "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", @@ -2176,6 +2077,12 @@ "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", "dev": true }, + "object-inspect": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.7.0.tgz", + "integrity": "sha512-a7pEHdh1xKIAgTySUGgLMx/xwDZskN1Ud6egYYN3EdRW4ZMPNEDUTF+hwy2LUC+Bl+SyLXANnwz/jyh/qutKUw==", + "dev": true + }, "object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", @@ -2195,13 +2102,66 @@ } }, "object.getownpropertydescriptors": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz", - "integrity": "sha1-h1jIRvW0B62rDyNuCYbxSwUcqhY=", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz", + "integrity": "sha512-Z53Oah9A3TdLoblT7VKJaTDdXdT+lQO+cNpKVnya5JDe9uLvzu1YyY1yFDFrcxrlRgWrEFH0jJtD/IbuwjcEVg==", "dev": true, "requires": { - "define-properties": "^1.1.2", - "es-abstract": "^1.5.1" + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1" + }, + "dependencies": { + "es-abstract": { + "version": "1.17.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.5.tgz", + "integrity": "sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", + "dev": true + }, + "is-callable": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", + "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==", + "dev": true + }, + "is-regex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.0.tgz", + "integrity": "sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + } } }, "once": { @@ -2219,30 +2179,6 @@ "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", "dev": true }, - "optimist": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", - "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", - "dev": true, - "requires": { - "minimist": "~0.0.1", - "wordwrap": "~0.0.2" - }, - "dependencies": { - "minimist": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", - "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", - "dev": true - }, - "wordwrap": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", - "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", - "dev": true - } - } - }, "optionator": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", @@ -2263,35 +2199,6 @@ "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "dev": true }, - "os-locale": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", - "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", - "dev": true, - "requires": { - "execa": "^1.0.0", - "lcid": "^2.0.0", - "mem": "^4.0.0" - } - }, - "p-defer": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", - "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", - "dev": true - }, - "p-finally": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", - "dev": true - }, - "p-is-promise": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", - "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==", - "dev": true - }, "p-limit": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", @@ -2344,12 +2251,6 @@ "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", "dev": true }, - "path-key": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", - "dev": true - }, "pause-stream": { "version": "0.0.11", "resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", @@ -2486,16 +2387,6 @@ "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==", "dev": true }, - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -2709,21 +2600,6 @@ "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, - "shebang-command": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", - "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", - "dev": true, - "requires": { - "shebang-regex": "^1.0.0" - } - }, - "shebang-regex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", - "dev": true - }, "shelljs": { "version": "0.7.8", "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.8.tgz", @@ -2811,12 +2687,6 @@ "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", "dev": true }, - "signal-exit": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", - "dev": true - }, "slice-ansi": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz", @@ -2867,7 +2737,7 @@ "standard": { "version": "10.0.3", "resolved": "https://registry.npmjs.org/standard/-/standard-10.0.3.tgz", - "integrity": "sha1-eGm8v0Ir3uqraJof+x/qlnfdUOo=", + "integrity": "sha512-JURZ+85ExKLQULckDFijdX5WHzN6RC7fgiZNSV4jFQVo+3tPoQGHyBrGekye/yf0aOfb4210EM5qPNlc2cRh4w==", "dev": true, "requires": { "eslint": "~3.19.0", @@ -2912,6 +2782,260 @@ "strip-ansi": "^3.0.0" } }, + "string.prototype.trimend": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz", + "integrity": "sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5" + }, + "dependencies": { + "es-abstract": { + "version": "1.17.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.5.tgz", + "integrity": "sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", + "dev": true + }, + "is-callable": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", + "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==", + "dev": true + }, + "is-regex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.0.tgz", + "integrity": "sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + } + } + }, + "string.prototype.trimleft": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.2.tgz", + "integrity": "sha512-gCA0tza1JBvqr3bfAIFJGqfdRTyPae82+KTnm3coDXkZN9wnuW3HjGgN386D7hfv5CHQYCI022/rJPVlqXyHSw==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5", + "string.prototype.trimstart": "^1.0.0" + }, + "dependencies": { + "es-abstract": { + "version": "1.17.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.5.tgz", + "integrity": "sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", + "dev": true + }, + "is-callable": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", + "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==", + "dev": true + }, + "is-regex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.0.tgz", + "integrity": "sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + } + } + }, + "string.prototype.trimright": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/string.prototype.trimright/-/string.prototype.trimright-2.1.2.tgz", + "integrity": "sha512-ZNRQ7sY3KroTaYjRS6EbNiiHrOkjihL9aQE/8gfQ4DtAC/aEBRHFJa44OmoWxGGqXuJlfKkZW4WcXErGr+9ZFg==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5", + "string.prototype.trimend": "^1.0.0" + }, + "dependencies": { + "es-abstract": { + "version": "1.17.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.5.tgz", + "integrity": "sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", + "dev": true + }, + "is-callable": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", + "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==", + "dev": true + }, + "is-regex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.0.tgz", + "integrity": "sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + } + } + }, + "string.prototype.trimstart": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz", + "integrity": "sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5" + }, + "dependencies": { + "es-abstract": { + "version": "1.17.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.5.tgz", + "integrity": "sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", + "dev": true + }, + "is-callable": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", + "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==", + "dev": true + }, + "is-regex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.0.tgz", + "integrity": "sha512-iI97M8KTWID2la5uYXlkbSDQIg4F6o1sYboZKKTDpnDQMLtUL86zxhgDet3Q2SriaYsyGqZ6Mn2SjbRKeLHdqw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + } + } + }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", @@ -2945,12 +3069,6 @@ "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", "dev": true }, - "strip-eof": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", - "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", - "dev": true - }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -3181,13 +3299,57 @@ "dev": true }, "wrap-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", - "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", + "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", "dev": true, "requires": { - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1" + "ansi-styles": "^3.2.0", + "string-width": "^3.0.0", + "strip-ansi": "^5.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } } }, "wrappy": { @@ -3224,22 +3386,21 @@ "dev": true }, "yargs": { - "version": "13.2.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.2.tgz", - "integrity": "sha512-WyEoxgyTD3w5XRpAQNYUB9ycVH/PQrToaTXdYXRdOXvEy1l19br+VJsc0vcO8PTGg5ro/l/GY7F/JMEBmI0BxA==", + "version": "13.3.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz", + "integrity": "sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw==", "dev": true, "requires": { - "cliui": "^4.0.0", + "cliui": "^5.0.0", "find-up": "^3.0.0", "get-caller-file": "^2.0.1", - "os-locale": "^3.1.0", "require-directory": "^2.1.1", "require-main-filename": "^2.0.0", "set-blocking": "^2.0.0", "string-width": "^3.0.0", "which-module": "^2.0.0", "y18n": "^4.0.0", - "yargs-parser": "^13.0.0" + "yargs-parser": "^13.1.2" }, "dependencies": { "ansi-regex": { @@ -3274,9 +3435,9 @@ } }, "p-limit": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", - "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", "dev": true, "requires": { "p-try": "^2.0.0" @@ -3320,9 +3481,9 @@ } }, "yargs-parser": { - "version": "13.0.0", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.0.0.tgz", - "integrity": "sha512-w2LXjoL8oRdRQN+hOyppuXs+V/fVAYtpcrRxZuF7Kt/Oc+Jr2uAcVntaUTNT6w5ihoWfFDpNY8CPx1QskxZ/pw==", + "version": "13.1.2", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz", + "integrity": "sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==", "dev": true, "requires": { "camelcase": "^5.0.0", @@ -3330,138 +3491,14 @@ } }, "yargs-unparser": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.5.0.tgz", - "integrity": "sha512-HK25qidFTCVuj/D1VfNiEndpLIeJN78aqgR23nL3y4N0U/91cOAzqfHlF8n2BvoNDcZmJKin3ddNSvOxSr8flw==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.6.0.tgz", + "integrity": "sha512-W9tKgmSn0DpSatfri0nx52Joq5hVXgeLiqR/5G0sZNDoLZFOr/xjBUDcShCOGNsBnEMNo1KAMBkTej1Hm62HTw==", "dev": true, "requires": { "flat": "^4.1.0", - "lodash": "^4.17.11", - "yargs": "^12.0.5" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "dev": true - }, - "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", - "dev": true, - "requires": { - "locate-path": "^3.0.0" - } - }, - "get-caller-file": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", - "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", - "dev": true - }, - "locate-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", - "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", - "dev": true, - "requires": { - "p-locate": "^3.0.0", - "path-exists": "^3.0.0" - } - }, - "lodash": { - "version": "4.17.12", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.12.tgz", - "integrity": "sha512-+CiwtLnsJhX03p20mwXuvhoebatoh5B3tt+VvYlrPgZC1g36y+RRbkufX95Xa+X4I59aWEacDFYwnJZiyBh9gA==", - "dev": true - }, - "p-limit": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", - "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", - "dev": true, - "requires": { - "p-try": "^2.0.0" - } - }, - "p-locate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", - "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", - "dev": true, - "requires": { - "p-limit": "^2.0.0" - } - }, - "p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true - }, - "require-main-filename": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", - "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", - "dev": true - }, - "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dev": true, - "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - } - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "dev": true, - "requires": { - "ansi-regex": "^3.0.0" - } - }, - "yargs": { - "version": "12.0.5", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-12.0.5.tgz", - "integrity": "sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw==", - "dev": true, - "requires": { - "cliui": "^4.0.0", - "decamelize": "^1.2.0", - "find-up": "^3.0.0", - "get-caller-file": "^1.0.1", - "os-locale": "^3.0.0", - "require-directory": "^2.1.1", - "require-main-filename": "^1.0.1", - "set-blocking": "^2.0.0", - "string-width": "^2.0.0", - "which-module": "^2.0.0", - "y18n": "^3.2.1 || ^4.0.0", - "yargs-parser": "^11.1.1" - } - }, - "yargs-parser": { - "version": "11.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-11.1.1.tgz", - "integrity": "sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ==", - "dev": true, - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - } - } + "lodash": "^4.17.15", + "yargs": "^13.3.0" } } } diff --git a/package.json b/package.json index 2ba65d4f3..638ccbb55 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.19.1", + "version": "1.21.0", "name": "httpsnippet", "description": "HTTP Request snippet generator for *most* languages", "author": "Ahmad Nassri (https://www.mashape.com/)", @@ -72,7 +72,7 @@ "echint": "^4.0.2", "glob": "^6.0.1", "istanbul": "^0.4.0", - "mocha": "^6.1.4", + "mocha": "^6.2.0", "require-directory": "^2.1.1", "should": "^13.2.3", "standard": "^10.0.2" diff --git a/src/index.js b/src/index.js index c50e35347..815593611 100644 --- a/src/index.js +++ b/src/index.js @@ -221,6 +221,32 @@ HTTPSnippet.prototype._matchTarget = function (target, client) { // exports module.exports = HTTPSnippet +module.exports.addTarget = function (target) { + if (!('info' in target)) { + throw new Error('The supplied custom target must contain an `info` object.') + } else if (!('key' in target.info) || !('title' in target.info) || !('extname' in target.info) || !('default' in target.info)) { + throw new Error('The supplied custom target must have an `info` object with a `key`, `title`, `extname`, and `default` property.') + } else if (targets.hasOwnProperty(target.info.key)) { + throw new Error('The supplied custom target already exists.') + } else if (Object.keys(target).length === 1) { + throw new Error('A custom target must have a client defined on it.') + } + + targets[target.info.key] = target +} + +module.exports.addTargetClient = function (target, client) { + if (!targets.hasOwnProperty(target)) { + throw new Error(`Sorry, but no ${target} target exists to add clients to.`) + } else if (!('info' in client)) { + throw new Error('The supplied custom target client must contain an `info` object.') + } else if (!('key' in client.info) || !('title' in client.info)) { + throw new Error('The supplied custom target client must have an `info` object with a `key` and `title` property.') + } + + targets[target][client.info.key] = client +} + module.exports.availableTargets = function () { return Object.keys(targets).map(function (key) { var target = Object.assign({}, targets[key].info) diff --git a/src/targets/csharp/httpclient.js b/src/targets/csharp/httpclient.js new file mode 100644 index 000000000..bff153c06 --- /dev/null +++ b/src/targets/csharp/httpclient.js @@ -0,0 +1,153 @@ +'use strict' + +var CodeBuilder = require('../../helpers/code-builder') + +function getDecompressionMethods (source) { + var acceptEncoding = source.allHeaders['accept-encoding'] + if (!acceptEncoding) { + return [] // no decompression + } + + var supportedMethods = { + gzip: 'DecompressionMethods.GZip', + deflate: 'DecompressionMethods.Deflate' + } + var methods = [] + acceptEncoding.split(',').forEach(function (encoding) { + var match = /\s*([^;\s]+)/.exec(encoding) + if (match) { + var method = supportedMethods[match[1]] + if (method) { + methods.push(method) + } + } + }) + + return methods +} + +module.exports = function (source, options) { + var indentation = ' ' + var code = new CodeBuilder(indentation) + + var clienthandler = '' + var cookies = !!source.allHeaders.cookie + var decompressionMethods = getDecompressionMethods(source) + if (cookies || decompressionMethods.length) { + clienthandler = 'clientHandler' + code.push('var clientHandler = new HttpClientHandler') + code.push('{') + if (cookies) { + // enable setting the cookie header + code.push(1, 'UseCookies = false,') + } + if (decompressionMethods.length) { + // enable decompression for supported methods + code.push(1, 'AutomaticDecompression = %s,', decompressionMethods.join(' | ')) + } + code.push('};') + } + + code.push('var client = new HttpClient(%s);', clienthandler) + + code.push('var request = new HttpRequestMessage') + code.push('{') + + var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE' ] + var method = source.method.toUpperCase() + if (method && (methods.indexOf(method) !== -1)) { + // buildin method + method = `HttpMethod.${method[0]}${method.substring(1).toLowerCase()}` + } else { + // custom method + method = `new HttpMethod("${method}")` + } + code.push(1, 'Method = %s,', method) + + code.push(1, 'RequestUri = new Uri("%s"),', source.fullUrl) + + var headers = Object.keys(source.allHeaders).filter(function (header) { + switch (header) { + case 'content-type': + case 'content-length': + case 'accept-encoding': + // skip these headers + return false + default: + return true + } + }) + if (headers.length) { + code.push(1, 'Headers =') + code.push(1, '{') + headers.forEach(function (key) { + code.push(2, '{ "%s", "%s" },', key, source.allHeaders[key]) + }) + code.push(1, '},') + } + + if (source.postData.text) { + const contentType = source.postData.mimeType + switch (contentType) { + case 'application/x-www-form-urlencoded': + code.push(1, 'Content = new FormUrlEncodedContent(new Dictionary') + code.push(1, '{') + source.postData.params.forEach(function (param) { + code.push(2, '{ "%s", "%s" },', param.name, param.value) + }) + code.push(1, '}),') + break + case 'multipart/form-data': + code.push(1, 'Content = new MultipartFormDataContent') + code.push(1, '{') + source.postData.params.forEach(function (param) { + code.push(2, 'new StringContent(%s)', JSON.stringify(param.value || '')) + code.push(2, '{') + code.push(3, 'Headers =') + code.push(3, '{') + if (param.contentType) { + code.push(4, 'ContentType = new MediaTypeHeaderValue("%s"),', param.contentType) + } + code.push(4, 'ContentDisposition = new ContentDispositionHeaderValue("form-data")') + code.push(4, '{') + code.push(5, 'Name = "%s",', param.name) + if (param.fileName) { + code.push(5, 'FileName = "%s",', param.fileName) + } + code.push(4, '}') + code.push(3, '}') + code.push(2, '},') + }) + + code.push(1, '},') + break + default: + code.push(1, 'Content = new StringContent(%s)', JSON.stringify(source.postData.text || '')) + code.push(1, '{') + code.push(2, 'Headers =') + code.push(2, '{') + code.push(3, 'ContentType = new MediaTypeHeaderValue("%s")', contentType) + code.push(2, '}') + code.push(1, '}') + break + } + } + code.push('};') + + // send and read response + code.push('using (var response = await client.SendAsync(request))') + code.push('{') + code.push(1, 'response.EnsureSuccessStatusCode();') + code.push(1, 'var body = await response.Content.ReadAsStringAsync();') + code.push(1, 'Console.WriteLine(body);') + code.push('}') + + return code.join() +} + +module.exports.info = { + key: 'httpclient', + title: 'HttpClient', + link: 'https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient', + description: '.NET Standard HTTP Client' +} diff --git a/src/targets/csharp/index.js b/src/targets/csharp/index.js index 226dd69f4..f266f466e 100644 --- a/src/targets/csharp/index.js +++ b/src/targets/csharp/index.js @@ -8,5 +8,6 @@ module.exports = { default: 'restsharp' }, - restsharp: require('./restsharp') + restsharp: require('./restsharp'), + httpclient: require('./httpclient') } diff --git a/src/targets/java/asynchttp.js b/src/targets/java/asynchttp.js index 3470e2a8b..cf3cd23c0 100644 --- a/src/targets/java/asynchttp.js +++ b/src/targets/java/asynchttp.js @@ -21,7 +21,7 @@ module.exports = function (source, options) { code.push('AsyncHttpClient client = new DefaultAsyncHttpClient();') - code.push(`client.prepare${source.method[0].toUpperCase()}${source.method.substring(1).toLowerCase()}("${source.fullUrl}")`) + code.push(`client.prepare("${source.method.toUpperCase()}", "${source.fullUrl}")`) // Add headers, including the cookies var headers = Object.keys(source.allHeaders) diff --git a/src/targets/java/index.js b/src/targets/java/index.js index 7efd9a989..37b0db718 100644 --- a/src/targets/java/index.js +++ b/src/targets/java/index.js @@ -10,6 +10,6 @@ module.exports = { okhttp: require('./okhttp'), unirest: require('./unirest'), - asynchttp: require('./asynchttp') - + asynchttp: require('./asynchttp'), + nethttp: require('./nethttp') } diff --git a/src/targets/java/nethttp.js b/src/targets/java/nethttp.js new file mode 100644 index 000000000..41e223dad --- /dev/null +++ b/src/targets/java/nethttp.js @@ -0,0 +1,63 @@ +/** + * @description + * HTTP code snippet generator for Java using java.net.http. + * + * @author + * @wtetsu + * + * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author. + */ + +'use strict' + +var CodeBuilder = require('../../helpers/code-builder') + +module.exports = function (source, options) { + var opts = Object.assign( + { + indent: ' ' + }, + options + ) + + var code = new CodeBuilder(opts.indent) + + code.push('HttpRequest request = HttpRequest.newBuilder()') + code.push(2, '.uri(URI.create("%s"))', source.fullUrl) + + var headers = Object.keys(source.allHeaders) + + // construct headers + if (headers.length) { + headers.forEach(function (key) { + code.push(2, '.header("%s", "%s")', key, source.allHeaders[key]) + }) + } + + if (source.postData.text) { + code.push( + 2, + '.method("%s", HttpRequest.BodyPublishers.ofString(%s))', + source.method.toUpperCase(), + JSON.stringify(source.postData.text) + ) + } else { + code.push(2, '.method("%s", HttpRequest.BodyPublishers.noBody())', source.method.toUpperCase()) + } + + code.push(2, '.build();') + + code.push( + 'HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());' + ) + code.push('System.out.println(response.body());') + + return code.join() +} + +module.exports.info = { + key: 'nethttp', + title: 'java.net.http', + link: 'https://openjdk.java.net/groups/net/httpclient/intro.html', + description: 'Java Standardized HTTP Client API' +} diff --git a/test/fixtures/available-targets.json b/test/fixtures/available-targets.json index ce59a15b1..261c48160 100644 --- a/test/fixtures/available-targets.json +++ b/test/fixtures/available-targets.json @@ -202,6 +202,12 @@ "title": "AsyncHttp", "link": "https://github.com/AsyncHttpClient/async-http-client", "description": "Asynchronous Http and WebSocket Client library for Java" + }, + { + "key": "nethttp", + "title": "java.net.http", + "link": "https://openjdk.java.net/groups/net/httpclient/intro.html", + "description": "Java Standardized HTTP Client API" } ] }, @@ -230,6 +236,12 @@ "title": "RestSharp", "link": "http://restsharp.org/", "description": "Simple REST and HTTP API Client for .NET" + }, + { + "key": "httpclient", + "title": "HttpClient", + "link": "https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient", + "description": ".NET Standard HTTP Client" } ] }, diff --git a/test/fixtures/customTarget.js b/test/fixtures/customTarget.js new file mode 100644 index 000000000..9a6e11c41 --- /dev/null +++ b/test/fixtures/customTarget.js @@ -0,0 +1,12 @@ +'use strict' + +module.exports = { + info: { + key: 'js-variant', + title: 'JavaScript Variant', + extname: '.js', + default: 'request' + }, + + request: require('../../src/targets/node/request') +} diff --git a/test/fixtures/output/csharp/httpclient/application-form-encoded.cs b/test/fixtures/output/csharp/httpclient/application-form-encoded.cs new file mode 100644 index 000000000..1fd11f8e0 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/application-form-encoded.cs @@ -0,0 +1,17 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Content = new FormUrlEncodedContent(new Dictionary + { + { "foo", "bar" }, + { "hello", "world" }, + }), +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/application-json.cs b/test/fixtures/output/csharp/httpclient/application-json.cs new file mode 100644 index 000000000..9bf3269f8 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/application-json.cs @@ -0,0 +1,19 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Content = new StringContent("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}") + { + Headers = + { + ContentType = new MediaTypeHeaderValue("application/json") + } + } +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/cookies.cs b/test/fixtures/output/csharp/httpclient/cookies.cs new file mode 100644 index 000000000..3ebced64e --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/cookies.cs @@ -0,0 +1,20 @@ +var clientHandler = new HttpClientHandler +{ + UseCookies = false, +}; +var client = new HttpClient(clientHandler); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Headers = + { + { "cookie", "foo=bar; bar=baz" }, + }, +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/custom-method.cs b/test/fixtures/output/csharp/httpclient/custom-method.cs new file mode 100644 index 000000000..a82173dac --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/custom-method.cs @@ -0,0 +1,12 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = new HttpMethod("PROPFIND"), + RequestUri = new Uri("http://mockbin.com/har"), +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/full.cs b/test/fixtures/output/csharp/httpclient/full.cs new file mode 100644 index 000000000..f1ae328b2 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/full.cs @@ -0,0 +1,25 @@ +var clientHandler = new HttpClientHandler +{ + UseCookies = false, +}; +var client = new HttpClient(clientHandler); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"), + Headers = + { + { "cookie", "foo=bar; bar=baz" }, + { "accept", "application/json" }, + }, + Content = new FormUrlEncodedContent(new Dictionary + { + { "foo", "bar" }, + }), +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/headers.cs b/test/fixtures/output/csharp/httpclient/headers.cs new file mode 100644 index 000000000..ad317d71e --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/headers.cs @@ -0,0 +1,17 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Get, + RequestUri = new Uri("http://mockbin.com/har"), + Headers = + { + { "accept", "application/json" }, + { "x-foo", "Bar" }, + }, +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/https.cs b/test/fixtures/output/csharp/httpclient/https.cs new file mode 100644 index 000000000..c36e055ef --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/https.cs @@ -0,0 +1,12 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Get, + RequestUri = new Uri("https://mockbin.com/har"), +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/jsonObj-multiline.cs b/test/fixtures/output/csharp/httpclient/jsonObj-multiline.cs new file mode 100644 index 000000000..dbd732960 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/jsonObj-multiline.cs @@ -0,0 +1,19 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Content = new StringContent("{\n \"foo\": \"bar\"\n}") + { + Headers = + { + ContentType = new MediaTypeHeaderValue("application/json") + } + } +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/jsonObj-null-value.cs b/test/fixtures/output/csharp/httpclient/jsonObj-null-value.cs new file mode 100644 index 000000000..f2451a477 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/jsonObj-null-value.cs @@ -0,0 +1,19 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Content = new StringContent("{\"foo\":null}") + { + Headers = + { + ContentType = new MediaTypeHeaderValue("application/json") + } + } +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/multipart-data.cs b/test/fixtures/output/csharp/httpclient/multipart-data.cs new file mode 100644 index 000000000..cba898143 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/multipart-data.cs @@ -0,0 +1,27 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Content = new MultipartFormDataContent + { + new StringContent("Hello World") + { + Headers = + { + ContentType = new MediaTypeHeaderValue("text/plain"), + ContentDisposition = new ContentDispositionHeaderValue("form-data") + { + Name = "foo", + FileName = "hello.txt", + } + } + }, + }, +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/multipart-file.cs b/test/fixtures/output/csharp/httpclient/multipart-file.cs new file mode 100644 index 000000000..b150479b6 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/multipart-file.cs @@ -0,0 +1,27 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Content = new MultipartFormDataContent + { + new StringContent("") + { + Headers = + { + ContentType = new MediaTypeHeaderValue("text/plain"), + ContentDisposition = new ContentDispositionHeaderValue("form-data") + { + Name = "foo", + FileName = "test/fixtures/files/hello.txt", + } + } + }, + }, +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/multipart-form-data.cs b/test/fixtures/output/csharp/httpclient/multipart-form-data.cs new file mode 100644 index 000000000..dafa4a1ff --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/multipart-form-data.cs @@ -0,0 +1,25 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Content = new MultipartFormDataContent + { + new StringContent("bar") + { + Headers = + { + ContentDisposition = new ContentDispositionHeaderValue("form-data") + { + Name = "foo", + } + } + }, + }, +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/query.cs b/test/fixtures/output/csharp/httpclient/query.cs new file mode 100644 index 000000000..702642147 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/query.cs @@ -0,0 +1,12 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Get, + RequestUri = new Uri("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"), +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/short.cs b/test/fixtures/output/csharp/httpclient/short.cs new file mode 100644 index 000000000..265b1967d --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/short.cs @@ -0,0 +1,12 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Get, + RequestUri = new Uri("http://mockbin.com/har"), +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/csharp/httpclient/text-plain.cs b/test/fixtures/output/csharp/httpclient/text-plain.cs new file mode 100644 index 000000000..cf56fa86f --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/text-plain.cs @@ -0,0 +1,19 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Post, + RequestUri = new Uri("http://mockbin.com/har"), + Content = new StringContent("Hello World") + { + Headers = + { + ContentType = new MediaTypeHeaderValue("text/plain") + } + } +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} diff --git a/test/fixtures/output/java/asynchttp/application-form-encoded.java b/test/fixtures/output/java/asynchttp/application-form-encoded.java index d93629d66..b4d515b1c 100644 --- a/test/fixtures/output/java/asynchttp/application-form-encoded.java +++ b/test/fixtures/output/java/asynchttp/application-form-encoded.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("content-type", "application/x-www-form-urlencoded") .setBody("foo=bar&hello=world") .execute() diff --git a/test/fixtures/output/java/asynchttp/application-json.java b/test/fixtures/output/java/asynchttp/application-json.java index da6efc208..1633e36c9 100644 --- a/test/fixtures/output/java/asynchttp/application-json.java +++ b/test/fixtures/output/java/asynchttp/application-json.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("content-type", "application/json") .setBody("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}") .execute() diff --git a/test/fixtures/output/java/asynchttp/cookies.java b/test/fixtures/output/java/asynchttp/cookies.java index b84e0b226..62b6eee43 100644 --- a/test/fixtures/output/java/asynchttp/cookies.java +++ b/test/fixtures/output/java/asynchttp/cookies.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("cookie", "foo=bar; bar=baz") .execute() .toCompletableFuture() diff --git a/test/fixtures/output/java/asynchttp/custom-method.java b/test/fixtures/output/java/asynchttp/custom-method.java index 50607d698..be1e9fc46 100644 --- a/test/fixtures/output/java/asynchttp/custom-method.java +++ b/test/fixtures/output/java/asynchttp/custom-method.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePropfind("http://mockbin.com/har") +client.prepare("PROPFIND", "http://mockbin.com/har") .execute() .toCompletableFuture() .thenAccept(System.out::println) diff --git a/test/fixtures/output/java/asynchttp/full.java b/test/fixtures/output/java/asynchttp/full.java index b1b67eba3..9fd2c6ffb 100644 --- a/test/fixtures/output/java/asynchttp/full.java +++ b/test/fixtures/output/java/asynchttp/full.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") +client.prepare("POST", "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") .setHeader("cookie", "foo=bar; bar=baz") .setHeader("accept", "application/json") .setHeader("content-type", "application/x-www-form-urlencoded") diff --git a/test/fixtures/output/java/asynchttp/headers.java b/test/fixtures/output/java/asynchttp/headers.java index f2600d581..472fe09bd 100644 --- a/test/fixtures/output/java/asynchttp/headers.java +++ b/test/fixtures/output/java/asynchttp/headers.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.prepareGet("http://mockbin.com/har") +client.prepare("GET", "http://mockbin.com/har") .setHeader("accept", "application/json") .setHeader("x-foo", "Bar") .execute() diff --git a/test/fixtures/output/java/asynchttp/https.java b/test/fixtures/output/java/asynchttp/https.java index b37516bc4..779198c27 100644 --- a/test/fixtures/output/java/asynchttp/https.java +++ b/test/fixtures/output/java/asynchttp/https.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.prepareGet("https://mockbin.com/har") +client.prepare("GET", "https://mockbin.com/har") .execute() .toCompletableFuture() .thenAccept(System.out::println) diff --git a/test/fixtures/output/java/asynchttp/jsonObj-multiline.java b/test/fixtures/output/java/asynchttp/jsonObj-multiline.java index 117dd9269..25f44e5cb 100644 --- a/test/fixtures/output/java/asynchttp/jsonObj-multiline.java +++ b/test/fixtures/output/java/asynchttp/jsonObj-multiline.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("content-type", "application/json") .setBody("{\n \"foo\": \"bar\"\n}") .execute() diff --git a/test/fixtures/output/java/asynchttp/jsonObj-null-value.java b/test/fixtures/output/java/asynchttp/jsonObj-null-value.java index 0b9f6bd3f..6d299feb9 100644 --- a/test/fixtures/output/java/asynchttp/jsonObj-null-value.java +++ b/test/fixtures/output/java/asynchttp/jsonObj-null-value.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("content-type", "application/json") .setBody("{\"foo\":null}") .execute() diff --git a/test/fixtures/output/java/asynchttp/multipart-data.java b/test/fixtures/output/java/asynchttp/multipart-data.java index f83cc9f79..50c9f504d 100644 --- a/test/fixtures/output/java/asynchttp/multipart-data.java +++ b/test/fixtures/output/java/asynchttp/multipart-data.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--\r\n") .execute() diff --git a/test/fixtures/output/java/asynchttp/multipart-file.java b/test/fixtures/output/java/asynchttp/multipart-file.java index 37ebe8c16..cee440818 100644 --- a/test/fixtures/output/java/asynchttp/multipart-file.java +++ b/test/fixtures/output/java/asynchttp/multipart-file.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n") .execute() diff --git a/test/fixtures/output/java/asynchttp/multipart-form-data.java b/test/fixtures/output/java/asynchttp/multipart-form-data.java index 41149bdbb..06c752bf2 100644 --- a/test/fixtures/output/java/asynchttp/multipart-form-data.java +++ b/test/fixtures/output/java/asynchttp/multipart-form-data.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n") .execute() diff --git a/test/fixtures/output/java/asynchttp/query.java b/test/fixtures/output/java/asynchttp/query.java index 428dbcf7e..524cbd27a 100644 --- a/test/fixtures/output/java/asynchttp/query.java +++ b/test/fixtures/output/java/asynchttp/query.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.prepareGet("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") +client.prepare("GET", "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") .execute() .toCompletableFuture() .thenAccept(System.out::println) diff --git a/test/fixtures/output/java/asynchttp/short.java b/test/fixtures/output/java/asynchttp/short.java index 30d448595..0ab245f40 100644 --- a/test/fixtures/output/java/asynchttp/short.java +++ b/test/fixtures/output/java/asynchttp/short.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.prepareGet("http://mockbin.com/har") +client.prepare("GET", "http://mockbin.com/har") .execute() .toCompletableFuture() .thenAccept(System.out::println) diff --git a/test/fixtures/output/java/asynchttp/text-plain.java b/test/fixtures/output/java/asynchttp/text-plain.java index b902d52a5..4b2cf1a61 100644 --- a/test/fixtures/output/java/asynchttp/text-plain.java +++ b/test/fixtures/output/java/asynchttp/text-plain.java @@ -1,5 +1,5 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); -client.preparePost("http://mockbin.com/har") +client.prepare("POST", "http://mockbin.com/har") .setHeader("content-type", "text/plain") .setBody("Hello World") .execute() diff --git a/test/fixtures/output/java/nethttp/application-form-encoded.java b/test/fixtures/output/java/nethttp/application-form-encoded.java new file mode 100644 index 000000000..bb31130e1 --- /dev/null +++ b/test/fixtures/output/java/nethttp/application-form-encoded.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("content-type", "application/x-www-form-urlencoded") + .method("POST", HttpRequest.BodyPublishers.ofString("foo=bar&hello=world")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/application-json.java b/test/fixtures/output/java/nethttp/application-json.java new file mode 100644 index 000000000..60e2402b8 --- /dev/null +++ b/test/fixtures/output/java/nethttp/application-json.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("content-type", "application/json") + .method("POST", HttpRequest.BodyPublishers.ofString("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/cookies.java b/test/fixtures/output/java/nethttp/cookies.java new file mode 100644 index 000000000..7aa98347d --- /dev/null +++ b/test/fixtures/output/java/nethttp/cookies.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("cookie", "foo=bar; bar=baz") + .method("POST", HttpRequest.BodyPublishers.noBody()) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/custom-method.java b/test/fixtures/output/java/nethttp/custom-method.java new file mode 100644 index 000000000..07e71ab10 --- /dev/null +++ b/test/fixtures/output/java/nethttp/custom-method.java @@ -0,0 +1,6 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .method("PROPFIND", HttpRequest.BodyPublishers.noBody()) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/full.java b/test/fixtures/output/java/nethttp/full.java new file mode 100644 index 000000000..b6e02eedd --- /dev/null +++ b/test/fixtures/output/java/nethttp/full.java @@ -0,0 +1,9 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")) + .header("cookie", "foo=bar; bar=baz") + .header("accept", "application/json") + .header("content-type", "application/x-www-form-urlencoded") + .method("POST", HttpRequest.BodyPublishers.ofString("foo=bar")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/headers.java b/test/fixtures/output/java/nethttp/headers.java new file mode 100644 index 000000000..2e8a09f87 --- /dev/null +++ b/test/fixtures/output/java/nethttp/headers.java @@ -0,0 +1,8 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("accept", "application/json") + .header("x-foo", "Bar") + .method("GET", HttpRequest.BodyPublishers.noBody()) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/https.java b/test/fixtures/output/java/nethttp/https.java new file mode 100644 index 000000000..a32c4305b --- /dev/null +++ b/test/fixtures/output/java/nethttp/https.java @@ -0,0 +1,6 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://mockbin.com/har")) + .method("GET", HttpRequest.BodyPublishers.noBody()) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/jsonObj-multiline.java b/test/fixtures/output/java/nethttp/jsonObj-multiline.java new file mode 100644 index 000000000..2a76e6bd6 --- /dev/null +++ b/test/fixtures/output/java/nethttp/jsonObj-multiline.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("content-type", "application/json") + .method("POST", HttpRequest.BodyPublishers.ofString("{\n \"foo\": \"bar\"\n}")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/jsonObj-null-value.java b/test/fixtures/output/java/nethttp/jsonObj-null-value.java new file mode 100644 index 000000000..14cc4f3c8 --- /dev/null +++ b/test/fixtures/output/java/nethttp/jsonObj-null-value.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("content-type", "application/json") + .method("POST", HttpRequest.BodyPublishers.ofString("{\"foo\":null}")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/multipart-data.java b/test/fixtures/output/java/nethttp/multipart-data.java new file mode 100644 index 000000000..f4cf85bfb --- /dev/null +++ b/test/fixtures/output/java/nethttp/multipart-data.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") + .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--\r\n")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/multipart-file.java b/test/fixtures/output/java/nethttp/multipart-file.java new file mode 100644 index 000000000..7c86e4be3 --- /dev/null +++ b/test/fixtures/output/java/nethttp/multipart-file.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") + .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/multipart-form-data.java b/test/fixtures/output/java/nethttp/multipart-form-data.java new file mode 100644 index 000000000..044bb716a --- /dev/null +++ b/test/fixtures/output/java/nethttp/multipart-form-data.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") + .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/query.java b/test/fixtures/output/java/nethttp/query.java new file mode 100644 index 000000000..7d8f106dd --- /dev/null +++ b/test/fixtures/output/java/nethttp/query.java @@ -0,0 +1,6 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")) + .method("GET", HttpRequest.BodyPublishers.noBody()) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/short.java b/test/fixtures/output/java/nethttp/short.java new file mode 100644 index 000000000..5e282c106 --- /dev/null +++ b/test/fixtures/output/java/nethttp/short.java @@ -0,0 +1,6 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .method("GET", HttpRequest.BodyPublishers.noBody()) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/fixtures/output/java/nethttp/text-plain.java b/test/fixtures/output/java/nethttp/text-plain.java new file mode 100644 index 000000000..634823835 --- /dev/null +++ b/test/fixtures/output/java/nethttp/text-plain.java @@ -0,0 +1,7 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har")) + .header("content-type", "text/plain") + .method("POST", HttpRequest.BodyPublishers.ofString("Hello World")) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); diff --git a/test/targets.js b/test/targets.js index 319dbe0e8..675293540 100644 --- a/test/targets.js +++ b/test/targets.js @@ -1,4 +1,4 @@ -/* global describe, it */ +/* global describe, it, beforeEach */ 'use strict' @@ -85,15 +85,105 @@ var itShouldGenerateOutput = function (request, path, target, client) { } describe('Available Targets', function () { - var targets = HTTPSnippet.availableTargets() - - targets.forEach(function (target) { + HTTPSnippet.availableTargets().forEach(function (target) { it('available-targets.json should include ' + target.title, function () { fixtures['available-targets'].should.containEql(target) }) }) }) +describe('Custom targets', function () { + describe('Adding a custom target', function () { + it('should throw if the target does has no info object', function () { + (function () { + HTTPSnippet.addTarget({}) + }).should.throw(Error) + }) + + it('should throw if the target does not have a properly constructed info object', function () { + (function () { + HTTPSnippet.addTarget({info: {key: ''}}) + }).should.throw(Error) + }) + + it('should throw if the target already exists', function () { + (function () { + HTTPSnippet.addTarget(targets.node) + }).should.throw(Error) + }) + + it('should throw if the target has no client', function () { + (function () { + HTTPSnippet.addTarget({ + info: targets.node.info + }) + }).should.throw(Error) + }) + + it('should add and convert for a new custom target', function () { + const customTarget = require('./fixtures/customTarget') + + HTTPSnippet.addTarget(customTarget) + const target = HTTPSnippet.availableTargets().find(function (target) { return target.key === customTarget.info.key }) + const client = target.clients.find(function (client) { return client.key === customTarget.info.default }) + client.should.be.an.Object() + + Object.keys(fixtures.requests).filter(clearInfo).forEach(function (request) { + // Re-using the `request` module fixtures and framework since we copied it to create a custom client. + itShouldGenerateOutput(request, 'node/request/', customTarget.info.key, customTarget.info.default) + }) + }) + }) + + describe('Adding a custom client target', function () { + let customClient + + beforeEach(function () { + // Re-using the existing request client instead of mocking out something completely new. + customClient = { + ...targets.node.request, + info: { + key: 'axios', + title: 'Axios', + link: 'https://www.npmjs.com/package/axios', + description: 'Promise based HTTP client for the browser and node.js' + } + } + }) + + it("should throw if the client's target does not exist", function () { + (function () { + HTTPSnippet.addTargetClient('node.js', customClient) + }).should.throw(Error) + }) + + it('should throw if the client does has no info object', function () { + (function () { + HTTPSnippet.addTargetClient('node', {}) + }).should.throw(Error) + }) + + it('should throw if the target does not have a properly constructed info object', function () { + (function () { + HTTPSnippet.addTargetClient('node', {info: {key: ''}}) + }).should.throw(Error) + }) + + it('should add and convert for a new custom client target', function () { + HTTPSnippet.addTargetClient('node', customClient) + + const target = HTTPSnippet.availableTargets().find(function (target) { return target.key === 'node' }) + const client = target.clients.find(function (client) { return client.key === customClient.info.key }) + client.should.be.an.Object() + + Object.keys(fixtures.requests).filter(clearInfo).forEach(function (request) { + // Re-using the `request` module fixtures and framework since we copied it to create a custom client target. + itShouldGenerateOutput(request, 'node/request/', 'node', customClient.info.key) + }) + }) + }) +}) + // test all the things! describe('Targets', function () { Object.keys(targets).forEach(function (target) { diff --git a/test/targets/csharp/httpclient.js b/test/targets/csharp/httpclient.js new file mode 100644 index 000000000..9ad8c1790 --- /dev/null +++ b/test/targets/csharp/httpclient.js @@ -0,0 +1,5 @@ +'use strict' + +require('should') + +module.exports = function (snippet, fixtures) {} diff --git a/test/targets/java/nethttp.js b/test/targets/java/nethttp.js new file mode 100644 index 000000000..9ad8c1790 --- /dev/null +++ b/test/targets/java/nethttp.js @@ -0,0 +1,5 @@ +'use strict' + +require('should') + +module.exports = function (snippet, fixtures) {}