@readme/httpsnippet 3.1.3 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -62
- package/dist/package.json +86 -0
- package/dist/src/fixtures/customTarget.js +15 -0
- package/dist/src/fixtures/mimetypes.js +77 -0
- package/dist/src/fixtures/requests/application-form-encoded.js +69 -0
- package/dist/src/fixtures/requests/application-json.js +72 -0
- package/dist/src/fixtures/requests/cookies.js +51 -0
- package/dist/src/fixtures/requests/custom-method.js +41 -0
- package/dist/src/fixtures/requests/full.js +99 -0
- package/dist/src/fixtures/requests/headers.js +56 -0
- package/dist/src/fixtures/requests/http-insecure.js +45 -0
- package/dist/src/fixtures/requests/jsonObj-multiline.js +59 -0
- package/dist/src/fixtures/requests/jsonObj-null-value.js +61 -0
- package/dist/src/fixtures/requests/multipart-data.js +72 -0
- package/dist/src/fixtures/requests/multipart-file.js +65 -0
- package/dist/src/fixtures/requests/multipart-form-data-no-params.js +56 -0
- package/dist/src/fixtures/requests/multipart-form-data.js +64 -0
- package/dist/src/fixtures/requests/nested.js +64 -0
- package/dist/src/fixtures/requests/query-encoded.js +59 -0
- package/dist/src/fixtures/requests/query.js +64 -0
- package/dist/src/fixtures/requests/short.js +45 -0
- package/dist/src/fixtures/requests/text-plain.js +57 -0
- package/dist/src/fixtures/runCustomFixtures.js +77 -0
- package/dist/src/helpers/code-builder.js +91 -0
- package/dist/src/helpers/form-data.js +157 -0
- package/dist/src/helpers/har-validator.js +76 -0
- package/dist/src/helpers/headers.js +33 -0
- package/dist/src/helpers/reducer.js +19 -0
- package/dist/src/helpers/shell.js +20 -0
- package/dist/src/helpers/utils.js +21 -0
- package/dist/src/index.js +285 -0
- package/dist/src/targets/c/libcurl/client.js +43 -0
- package/dist/src/targets/c/target.js +15 -0
- package/dist/src/targets/clojure/clj_http/client.js +184 -0
- package/dist/src/targets/clojure/target.js +15 -0
- package/dist/src/targets/csharp/httpclient/client.js +162 -0
- package/dist/src/targets/csharp/restsharp/client.js +38 -0
- package/dist/src/targets/csharp/target.js +17 -0
- package/dist/src/targets/go/native/client.js +122 -0
- package/dist/src/targets/go/target.js +15 -0
- package/dist/src/targets/http/http1.1/client.js +79 -0
- package/dist/src/targets/http/target.js +15 -0
- package/dist/src/targets/java/asynchttp/client.js +53 -0
- package/dist/src/targets/java/nethttp/client.js +52 -0
- package/dist/src/targets/java/okhttp/client.js +79 -0
- package/dist/src/targets/java/target.js +21 -0
- package/dist/src/targets/java/unirest/client.js +53 -0
- package/dist/src/targets/javascript/axios/client.js +101 -0
- package/dist/src/targets/javascript/axios/fixtures/application-form-encoded.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/application-json.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/cookies.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/custom-method.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/full.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/headers.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/http-insecure.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-data.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-file.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/nested.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/query-encoded.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/query.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/short.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/text-plain.js +19 -0
- package/dist/src/targets/javascript/fetch/client.js +115 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-form-encoded.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-json.js +16 -0
- package/dist/src/targets/javascript/fetch/fixtures/cookies.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/custom-method.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/full.js +13 -0
- package/dist/src/targets/javascript/fetch/fixtures/headers.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/http-insecure.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-data.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-file.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/nested.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query-encoded.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/short.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/text-plain.js +5 -0
- package/dist/src/targets/javascript/jquery/client.js +93 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/full.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/headers.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-data.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-file.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
- package/dist/src/targets/javascript/target.js +21 -0
- package/dist/src/targets/javascript/xhr/client.js +90 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-form-encoded.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-json.js +31 -0
- package/dist/src/targets/javascript/xhr/fixtures/cookies.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/cors.js +10 -0
- package/dist/src/targets/javascript/xhr/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/full.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/headers.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/text-plain.js +12 -0
- package/dist/src/targets/kotlin/okhttp/client.js +79 -0
- package/dist/src/targets/kotlin/target.js +15 -0
- package/dist/src/targets/node/axios/client.js +87 -0
- package/dist/src/targets/node/axios/fixtures/application-form-encoded.js +19 -0
- package/dist/src/targets/node/axios/fixtures/application-json.js +22 -0
- package/dist/src/targets/node/axios/fixtures/cookies.js +14 -0
- package/dist/src/targets/node/axios/fixtures/custom-method.js +10 -0
- package/dist/src/targets/node/axios/fixtures/full.js +22 -0
- package/dist/src/targets/node/axios/fixtures/headers.js +14 -0
- package/dist/src/targets/node/axios/fixtures/http-insecure.js +10 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-file.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +14 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/nested.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query-encoded.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query.js +13 -0
- package/dist/src/targets/node/axios/fixtures/short.js +10 -0
- package/dist/src/targets/node/axios/fixtures/text-plain.js +15 -0
- package/dist/src/targets/node/fetch/client.js +149 -0
- package/dist/src/targets/node/fetch/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/fetch/fixtures/application-json.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/cookies.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/custom-method.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/full.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/headers.js +10 -0
- package/dist/src/targets/node/fetch/fixtures/http-insecure.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-multiline.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-null-value.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/nested.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query-encoded.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/short.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/text-plain.js +7 -0
- package/dist/src/targets/node/native/client.js +91 -0
- package/dist/src/targets/node/native/fixtures/application-form-encoded.js +24 -0
- package/dist/src/targets/node/native/fixtures/application-json.js +30 -0
- package/dist/src/targets/node/native/fixtures/cookies.js +22 -0
- package/dist/src/targets/node/native/fixtures/custom-method.js +20 -0
- package/dist/src/targets/node/native/fixtures/full.js +26 -0
- package/dist/src/targets/node/native/fixtures/headers.js +24 -0
- package/dist/src/targets/node/native/fixtures/http-insecure.js +20 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-multiline.js +23 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-null-value.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-file.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data-no-params.js +22 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/nested.js +20 -0
- package/dist/src/targets/node/native/fixtures/query-encoded.js +20 -0
- package/dist/src/targets/node/native/fixtures/query.js +20 -0
- package/dist/src/targets/node/native/fixtures/short.js +20 -0
- package/dist/src/targets/node/native/fixtures/text-plain.js +23 -0
- package/dist/src/targets/node/request/client.js +116 -0
- package/dist/src/targets/node/request/fixtures/application-form-encoded.js +13 -0
- package/dist/src/targets/node/request/fixtures/application-json.js +21 -0
- package/dist/src/targets/node/request/fixtures/cookies.js +11 -0
- package/dist/src/targets/node/request/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/request/fixtures/full.js +20 -0
- package/dist/src/targets/node/request/fixtures/headers.js +12 -0
- package/dist/src/targets/node/request/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/node/request/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/request/fixtures/multipart-file.js +19 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data-no-params.js +12 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data.js +13 -0
- package/dist/src/targets/node/request/fixtures/nested.js +11 -0
- package/dist/src/targets/node/request/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/node/request/fixtures/query.js +11 -0
- package/dist/src/targets/node/request/fixtures/short.js +8 -0
- package/dist/src/targets/node/request/fixtures/text-plain.js +13 -0
- package/dist/src/targets/node/target.js +24 -0
- package/dist/src/targets/node/unirest/client.js +119 -0
- package/dist/src/targets/node/unirest/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/application-json.js +32 -0
- package/dist/src/targets/node/unirest/fixtures/cookies.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/full.js +27 -0
- package/dist/src/targets/node/unirest/fixtures/headers.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-file.js +18 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/nested.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/query-encoded.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/query.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/short.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/text-plain.js +12 -0
- package/dist/src/targets/objc/helpers.js +59 -0
- package/dist/src/targets/objc/nsurlsession/client.js +151 -0
- package/dist/src/targets/objc/target.js +15 -0
- package/dist/src/targets/ocaml/cohttp/client.js +72 -0
- package/dist/src/targets/ocaml/target.js +15 -0
- package/dist/src/targets/php/curl/client.js +135 -0
- package/dist/src/targets/php/guzzle/client.js +126 -0
- package/dist/src/targets/php/helpers.js +63 -0
- package/dist/src/targets/php/http1/client.js +90 -0
- package/dist/src/targets/php/http2/client.js +128 -0
- package/dist/src/targets/php/target.js +22 -0
- package/dist/src/targets/powershell/common.js +49 -0
- package/dist/src/targets/powershell/restmethod/client.js +13 -0
- package/dist/src/targets/powershell/target.js +17 -0
- package/dist/src/targets/powershell/webrequest/client.js +13 -0
- package/dist/src/targets/python/helpers.js +70 -0
- package/dist/src/targets/python/requests/client.js +161 -0
- package/dist/src/targets/python/target.js +16 -0
- package/dist/src/targets/r/httr/client.js +125 -0
- package/dist/src/targets/r/target.js +15 -0
- package/dist/src/targets/ruby/native/client.js +69 -0
- package/dist/src/targets/ruby/target.js +15 -0
- package/dist/src/targets/shell/curl/client.js +171 -0
- package/dist/src/targets/shell/httpie/client.js +111 -0
- package/dist/src/targets/shell/target.js +20 -0
- package/dist/src/targets/shell/wget/client.js +55 -0
- package/dist/src/targets/swift/helpers.js +80 -0
- package/dist/src/targets/swift/nsurlsession/client.js +156 -0
- package/dist/src/targets/swift/target.js +15 -0
- package/dist/src/targets/targets.js +130 -0
- package/package.json +26 -21
- package/src/helpers/code-builder.js +0 -108
- package/src/helpers/form-data.js +0 -107
- package/src/helpers/headers.js +0 -48
- package/src/helpers/reducer.js +0 -20
- package/src/index.js +0 -361
- package/src/targets/c/index.js +0 -10
- package/src/targets/c/libcurl.js +0 -45
- package/src/targets/clojure/clj_http.js +0 -176
- package/src/targets/clojure/index.js +0 -10
- package/src/targets/csharp/httpclient.js +0 -157
- package/src/targets/csharp/index.js +0 -11
- package/src/targets/csharp/restsharp.js +0 -49
- package/src/targets/go/index.js +0 -10
- package/src/targets/go/native.js +0 -130
- package/src/targets/http/http1.1.js +0 -89
- package/src/targets/http/index.js +0 -10
- package/src/targets/index.js +0 -20
- package/src/targets/java/asynchttp.js +0 -54
- package/src/targets/java/index.js +0 -13
- package/src/targets/java/nethttp.js +0 -59
- package/src/targets/java/okhttp.js +0 -78
- package/src/targets/java/unirest.js +0 -57
- package/src/targets/javascript/axios.js +0 -101
- package/src/targets/javascript/fetch.js +0 -129
- package/src/targets/javascript/index.js +0 -13
- package/src/targets/javascript/jquery.js +0 -89
- package/src/targets/javascript/xhr.js +0 -86
- package/src/targets/kotlin/index.js +0 -10
- package/src/targets/kotlin/okhttp.js +0 -78
- package/src/targets/node/axios.js +0 -76
- package/src/targets/node/fetch.js +0 -145
- package/src/targets/node/index.js +0 -15
- package/src/targets/node/native.js +0 -92
- package/src/targets/node/request.js +0 -126
- package/src/targets/node/unirest.js +0 -120
- package/src/targets/objc/helpers.js +0 -80
- package/src/targets/objc/index.js +0 -10
- package/src/targets/objc/nsurlsession.js +0 -164
- package/src/targets/ocaml/cohttp.js +0 -73
- package/src/targets/ocaml/index.js +0 -10
- package/src/targets/php/curl.js +0 -142
- package/src/targets/php/guzzle.js +0 -135
- package/src/targets/php/helpers.js +0 -87
- package/src/targets/php/http1.js +0 -85
- package/src/targets/php/http2.js +0 -131
- package/src/targets/php/index.js +0 -14
- package/src/targets/powershell/common.js +0 -60
- package/src/targets/powershell/index.js +0 -11
- package/src/targets/powershell/restmethod.js +0 -8
- package/src/targets/powershell/webrequest.js +0 -8
- package/src/targets/python/helpers.js +0 -85
- package/src/targets/python/index.js +0 -11
- package/src/targets/python/requests.js +0 -163
- package/src/targets/r/httr.js +0 -134
- package/src/targets/r/index.js +0 -10
- package/src/targets/ruby/index.js +0 -10
- package/src/targets/ruby/native.js +0 -71
- package/src/targets/shell/curl.js +0 -157
- package/src/targets/shell/helpers.js +0 -23
- package/src/targets/shell/httpie.js +0 -129
- package/src/targets/shell/index.js +0 -13
- package/src/targets/shell/wget.js +0 -52
- package/src/targets/swift/helpers.js +0 -93
- package/src/targets/swift/index.js +0 -10
- package/src/targets/swift/nsurlsession.js +0 -152
package/src/index.js
DELETED
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
const es = require('event-stream');
|
|
2
|
-
const MultiPartForm = require('form-data');
|
|
3
|
-
const qs = require('qs');
|
|
4
|
-
const reducer = require('./helpers/reducer');
|
|
5
|
-
const helpers = require('./helpers/headers');
|
|
6
|
-
const targets = require('./targets');
|
|
7
|
-
const url = require('url');
|
|
8
|
-
const validate = require('har-validator/lib/async');
|
|
9
|
-
|
|
10
|
-
const { formDataIterator, isBlob } = require('./helpers/form-data');
|
|
11
|
-
|
|
12
|
-
// constructor
|
|
13
|
-
const HTTPSnippet = function (data, opts = {}) {
|
|
14
|
-
let entries;
|
|
15
|
-
const self = this;
|
|
16
|
-
const input = { ...data };
|
|
17
|
-
|
|
18
|
-
const options = {
|
|
19
|
-
harIsAlreadyEncoded: false,
|
|
20
|
-
...opts,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// prep the main container
|
|
24
|
-
self.requests = [];
|
|
25
|
-
|
|
26
|
-
// is it har?
|
|
27
|
-
if (input.log && input.log.entries) {
|
|
28
|
-
entries = input.log.entries;
|
|
29
|
-
} else {
|
|
30
|
-
entries = [
|
|
31
|
-
{
|
|
32
|
-
request: input,
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
entries.forEach(function (entry) {
|
|
38
|
-
const request = { ...entry.request };
|
|
39
|
-
|
|
40
|
-
// add optional properties to make validation successful
|
|
41
|
-
request.httpVersion = request.httpVersion || 'HTTP/1.1';
|
|
42
|
-
request.queryString = request.queryString || [];
|
|
43
|
-
request.headers = request.headers || [];
|
|
44
|
-
request.cookies = request.cookies || [];
|
|
45
|
-
request.postData = request.postData || {};
|
|
46
|
-
request.postData.mimeType = request.postData.mimeType || 'application/octet-stream';
|
|
47
|
-
|
|
48
|
-
request.bodySize = 0;
|
|
49
|
-
request.headersSize = 0;
|
|
50
|
-
request.postData.size = 0;
|
|
51
|
-
|
|
52
|
-
validate.request(request, function (err, valid) {
|
|
53
|
-
if (!valid) {
|
|
54
|
-
throw err;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
self.requests.push(self.prepare(request, options));
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
HTTPSnippet.prototype.prepare = function (request, options) {
|
|
63
|
-
// construct utility properties
|
|
64
|
-
request.queryObj = {};
|
|
65
|
-
request.headersObj = {};
|
|
66
|
-
request.cookiesObj = {};
|
|
67
|
-
request.allHeaders = {};
|
|
68
|
-
request.postData.jsonObj = false;
|
|
69
|
-
request.postData.paramsObj = false;
|
|
70
|
-
|
|
71
|
-
// construct query objects
|
|
72
|
-
if (request.queryString && request.queryString.length) {
|
|
73
|
-
request.queryObj = request.queryString.reduce(reducer, {});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// construct headers objects
|
|
77
|
-
if (request.headers && request.headers.length) {
|
|
78
|
-
const http2VersionRegex = /^HTTP\/2/;
|
|
79
|
-
request.headersObj = request.headers.reduce(function (headers, header) {
|
|
80
|
-
let headerName = header.name;
|
|
81
|
-
if (request.httpVersion.match(http2VersionRegex)) {
|
|
82
|
-
headerName = headerName.toLowerCase();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// eslint-disable-next-line no-param-reassign
|
|
86
|
-
headers[headerName] = header.value;
|
|
87
|
-
return headers;
|
|
88
|
-
}, {});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// construct headers objects
|
|
92
|
-
if (request.cookies && request.cookies.length) {
|
|
93
|
-
request.cookiesObj = request.cookies.reduceRight(function (cookies, cookie) {
|
|
94
|
-
// eslint-disable-next-line no-param-reassign
|
|
95
|
-
cookies[cookie.name] = cookie.value;
|
|
96
|
-
return cookies;
|
|
97
|
-
}, {});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// construct Cookie header
|
|
101
|
-
const cookies = request.cookies.map(function (cookie) {
|
|
102
|
-
if (options.harIsAlreadyEncoded) {
|
|
103
|
-
return `${cookie.name}=${cookie.value}`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`;
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
if (cookies.length) {
|
|
110
|
-
request.allHeaders.cookie = cookies.join('; ');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
switch (request.postData.mimeType) {
|
|
114
|
-
case 'multipart/mixed':
|
|
115
|
-
case 'multipart/related':
|
|
116
|
-
case 'multipart/form-data':
|
|
117
|
-
case 'multipart/alternative':
|
|
118
|
-
// reset values
|
|
119
|
-
request.postData.text = '';
|
|
120
|
-
request.postData.mimeType = 'multipart/form-data';
|
|
121
|
-
|
|
122
|
-
if (request.postData.params) {
|
|
123
|
-
const form = new MultiPartForm();
|
|
124
|
-
|
|
125
|
-
// The `form-data` module returns one of two things: a native FormData object, or its own polyfill. Since the
|
|
126
|
-
// polyfill does not support the full API of the native FormData object, when this library is running in a
|
|
127
|
-
// browser environment it'll fail on two things:
|
|
128
|
-
//
|
|
129
|
-
// - The API for `form.append()` has three arguments and the third should only be present when the second is a
|
|
130
|
-
// Blob or USVString.
|
|
131
|
-
// - `FormData.pipe()` isn't a function.
|
|
132
|
-
//
|
|
133
|
-
// Since the native FormData object is iterable, we easily detect what version of `form-data` we're working
|
|
134
|
-
// with here to allow `multipart/form-data` requests to be compiled under both browser and Node environments.
|
|
135
|
-
//
|
|
136
|
-
// This hack is pretty awful but it's the only way we can use this library in the browser as if we code this
|
|
137
|
-
// against just the native FormData object, we can't polyfill that back into Node because Blob and File objects,
|
|
138
|
-
// which something like `formdata-polyfill` requires, don't exist there.
|
|
139
|
-
const isNativeFormData = typeof form[Symbol.iterator] === 'function';
|
|
140
|
-
|
|
141
|
-
// easter egg
|
|
142
|
-
const boundary = '---011000010111000001101001';
|
|
143
|
-
if (!isNativeFormData) {
|
|
144
|
-
form._boundary = boundary;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
request.postData.params.forEach(function (param) {
|
|
148
|
-
const name = param.name;
|
|
149
|
-
const value = param.value || '';
|
|
150
|
-
const filename = param.fileName || null;
|
|
151
|
-
|
|
152
|
-
if (isNativeFormData) {
|
|
153
|
-
if (isBlob(value)) {
|
|
154
|
-
form.append(name, value, filename);
|
|
155
|
-
} else {
|
|
156
|
-
form.append(name, value);
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
form.append(name, value, {
|
|
160
|
-
filename: filename,
|
|
161
|
-
contentType: param.contentType || null,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
if (isNativeFormData) {
|
|
167
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
168
|
-
for (const data of formDataIterator(form, boundary)) {
|
|
169
|
-
request.postData.text += data;
|
|
170
|
-
}
|
|
171
|
-
} else {
|
|
172
|
-
form.pipe(
|
|
173
|
-
// eslint-disable-next-line array-callback-return
|
|
174
|
-
es.map(function (data) {
|
|
175
|
-
request.postData.text += data;
|
|
176
|
-
})
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
request.postData.boundary = boundary;
|
|
181
|
-
|
|
182
|
-
// Since headers are case-sensitive we need to see if there's an existing `Content-Type` header that we can
|
|
183
|
-
// override.
|
|
184
|
-
const contentTypeHeader = helpers.hasHeader(request.headersObj, 'content-type')
|
|
185
|
-
? helpers.getHeaderName(request.headersObj, 'content-type')
|
|
186
|
-
: 'content-type';
|
|
187
|
-
|
|
188
|
-
request.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
|
|
192
|
-
case 'application/x-www-form-urlencoded':
|
|
193
|
-
if (!request.postData.params) {
|
|
194
|
-
request.postData.text = '';
|
|
195
|
-
} else {
|
|
196
|
-
request.postData.paramsObj = request.postData.params.reduce(reducer, {});
|
|
197
|
-
|
|
198
|
-
// always overwrite
|
|
199
|
-
request.postData.text = qs.stringify(request.postData.paramsObj);
|
|
200
|
-
}
|
|
201
|
-
break;
|
|
202
|
-
|
|
203
|
-
case 'text/json':
|
|
204
|
-
case 'text/x-json':
|
|
205
|
-
case 'application/json':
|
|
206
|
-
case 'application/x-json':
|
|
207
|
-
request.postData.mimeType = 'application/json';
|
|
208
|
-
|
|
209
|
-
if (request.postData.text) {
|
|
210
|
-
try {
|
|
211
|
-
request.postData.jsonObj = JSON.parse(request.postData.text);
|
|
212
|
-
} catch (e) {
|
|
213
|
-
// force back to text/plain
|
|
214
|
-
// if headers have proper content-type value, then this should also work
|
|
215
|
-
request.postData.mimeType = 'text/plain';
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
break;
|
|
219
|
-
|
|
220
|
-
default:
|
|
221
|
-
// no-op
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// create allHeaders object
|
|
225
|
-
request.allHeaders = Object.assign(request.allHeaders, request.headersObj);
|
|
226
|
-
|
|
227
|
-
// deconstruct the uri
|
|
228
|
-
// eslint-disable-next-line node/no-deprecated-api
|
|
229
|
-
request.uriObj = url.parse(request.url, true, true);
|
|
230
|
-
|
|
231
|
-
// merge all possible queryString values
|
|
232
|
-
request.queryObj = Object.assign(request.queryObj, request.uriObj.query);
|
|
233
|
-
|
|
234
|
-
// reset uriObj values for a clean url
|
|
235
|
-
request.uriObj.query = null;
|
|
236
|
-
request.uriObj.search = null;
|
|
237
|
-
request.uriObj.path = request.uriObj.pathname;
|
|
238
|
-
|
|
239
|
-
// keep the base url clean of queryString
|
|
240
|
-
request.url = url.format(request.uriObj);
|
|
241
|
-
|
|
242
|
-
// update the uri object
|
|
243
|
-
request.uriObj.query = request.queryObj;
|
|
244
|
-
if (options.harIsAlreadyEncoded) {
|
|
245
|
-
request.uriObj.search = qs.stringify(request.queryObj, {
|
|
246
|
-
encode: false,
|
|
247
|
-
indices: false,
|
|
248
|
-
});
|
|
249
|
-
} else {
|
|
250
|
-
request.uriObj.search = qs.stringify(request.queryObj, {
|
|
251
|
-
indices: false,
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (request.uriObj.search) {
|
|
256
|
-
request.uriObj.path = `${request.uriObj.pathname}?${request.uriObj.search}`;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// construct a full url
|
|
260
|
-
request.fullUrl = url.format(request.uriObj);
|
|
261
|
-
|
|
262
|
-
return request;
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
HTTPSnippet.prototype.convert = function (target, client, opts) {
|
|
266
|
-
if (!opts && client) {
|
|
267
|
-
// eslint-disable-next-line no-param-reassign
|
|
268
|
-
opts = client;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const func = this._matchTarget(target, client);
|
|
272
|
-
if (func) {
|
|
273
|
-
const results = this.requests.map(function (request) {
|
|
274
|
-
return func(request, opts);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
return results.length === 1 ? results[0] : results;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return false;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
HTTPSnippet.prototype._matchTarget = function (target, client) {
|
|
284
|
-
// does it exist?
|
|
285
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
286
|
-
if (!targets.hasOwnProperty(target)) {
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// shorthand
|
|
291
|
-
if (typeof client === 'string' && typeof targets[target][client] === 'function') {
|
|
292
|
-
return targets[target][client];
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// default target
|
|
296
|
-
return targets[target][targets[target].info.default];
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
// exports
|
|
300
|
-
module.exports = HTTPSnippet;
|
|
301
|
-
|
|
302
|
-
module.exports.addTarget = function (target) {
|
|
303
|
-
if (!('info' in target)) {
|
|
304
|
-
throw new Error('The supplied custom target must contain an `info` object.');
|
|
305
|
-
} else if (
|
|
306
|
-
!('key' in target.info) ||
|
|
307
|
-
!('title' in target.info) ||
|
|
308
|
-
!('extname' in target.info) ||
|
|
309
|
-
!('default' in target.info)
|
|
310
|
-
) {
|
|
311
|
-
throw new Error(
|
|
312
|
-
'The supplied custom target must have an `info` object with a `key`, `title`, `extname`, and `default` property.'
|
|
313
|
-
);
|
|
314
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
315
|
-
} else if (targets.hasOwnProperty(target.info.key)) {
|
|
316
|
-
throw new Error('The supplied custom target already exists.');
|
|
317
|
-
} else if (Object.keys(target).length === 1) {
|
|
318
|
-
throw new Error('A custom target must have a client defined on it.');
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
targets[target.info.key] = target;
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
module.exports.addTargetClient = function (target, client) {
|
|
325
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
326
|
-
if (!targets.hasOwnProperty(target)) {
|
|
327
|
-
throw new Error(`Sorry, but no ${target} target exists to add clients to.`);
|
|
328
|
-
} else if (!('info' in client)) {
|
|
329
|
-
throw new Error('The supplied custom target client must contain an `info` object.');
|
|
330
|
-
} else if (!('key' in client.info) || !('title' in client.info)) {
|
|
331
|
-
throw new Error('The supplied custom target client must have an `info` object with a `key` and `title` property.');
|
|
332
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
333
|
-
} else if (targets[target].hasOwnProperty(client.info.key)) {
|
|
334
|
-
throw new Error('The supplied custom target client already exists, please use a different key');
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
targets[target][client.info.key] = client;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
module.exports.availableTargets = function () {
|
|
341
|
-
return Object.keys(targets).map(function (key) {
|
|
342
|
-
const target = { ...targets[key].info };
|
|
343
|
-
const clients = Object.keys(targets[key])
|
|
344
|
-
.filter(function (prop) {
|
|
345
|
-
return !['info', 'index'].includes(prop);
|
|
346
|
-
})
|
|
347
|
-
.map(function (client) {
|
|
348
|
-
return targets[key][client].info;
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
if (clients.length) {
|
|
352
|
-
target.clients = clients;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return target;
|
|
356
|
-
});
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
module.exports.extname = function (target) {
|
|
360
|
-
return targets[target] ? targets[target].info.extname : '';
|
|
361
|
-
};
|
package/src/targets/c/index.js
DELETED
package/src/targets/c/libcurl.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
2
|
-
|
|
3
|
-
module.exports = function (source) {
|
|
4
|
-
const code = new CodeBuilder();
|
|
5
|
-
|
|
6
|
-
code
|
|
7
|
-
.push('CURL *hnd = curl_easy_init();')
|
|
8
|
-
.blank()
|
|
9
|
-
.push('curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "%s");', source.method.toUpperCase())
|
|
10
|
-
.push('curl_easy_setopt(hnd, CURLOPT_URL, "%s");', source.fullUrl);
|
|
11
|
-
|
|
12
|
-
// Add headers, including the cookies
|
|
13
|
-
const headers = Object.keys(source.headersObj);
|
|
14
|
-
|
|
15
|
-
// construct headers
|
|
16
|
-
if (headers.length) {
|
|
17
|
-
code.blank().push('struct curl_slist *headers = NULL;');
|
|
18
|
-
|
|
19
|
-
headers.forEach(function (key) {
|
|
20
|
-
code.push('headers = curl_slist_append(headers, "%s: %s");', key, source.headersObj[key]);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
code.push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// construct cookies
|
|
27
|
-
if (source.allHeaders.cookie) {
|
|
28
|
-
code.blank().push('curl_easy_setopt(hnd, CURLOPT_COOKIE, "%s");', source.allHeaders.cookie);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (source.postData.text) {
|
|
32
|
-
code.blank().push('curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, %s);', JSON.stringify(source.postData.text));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
code.blank().push('CURLcode ret = curl_easy_perform(hnd);');
|
|
36
|
-
|
|
37
|
-
return code.join();
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
module.exports.info = {
|
|
41
|
-
key: 'libcurl',
|
|
42
|
-
title: 'Libcurl',
|
|
43
|
-
link: 'http://curl.haxx.se/libcurl/',
|
|
44
|
-
description: 'Simple REST and HTTP API Client for C',
|
|
45
|
-
};
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for Clojure using clj-http.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @tggreene
|
|
7
|
-
*
|
|
8
|
-
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
12
|
-
const helpers = require('../../helpers/headers');
|
|
13
|
-
|
|
14
|
-
const Keyword = function (name) {
|
|
15
|
-
this.name = name;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
Keyword.prototype.toString = function () {
|
|
19
|
-
return `:${this.name}`;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const File = function (path) {
|
|
23
|
-
this.path = path;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
File.prototype.toString = function () {
|
|
27
|
-
return `(clojure.java.io/file "${this.path}")`;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const jsType = function (x) {
|
|
31
|
-
return typeof x !== 'undefined' ? x.constructor.name.toLowerCase() : null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const objEmpty = function (x) {
|
|
35
|
-
return jsType(x) === 'object' ? Object.keys(x).length === 0 : false;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const filterEmpty = function (m) {
|
|
39
|
-
Object.keys(m)
|
|
40
|
-
.filter(function (x) {
|
|
41
|
-
return objEmpty(m[x]);
|
|
42
|
-
})
|
|
43
|
-
.forEach(function (x) {
|
|
44
|
-
// eslint-disable-next-line no-param-reassign
|
|
45
|
-
delete m[x];
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return m;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const padBlock = function (x, s) {
|
|
52
|
-
// eslint-disable-next-line prefer-spread
|
|
53
|
-
const padding = Array.apply(null, new Array(x))
|
|
54
|
-
.map(function () {
|
|
55
|
-
return ' ';
|
|
56
|
-
})
|
|
57
|
-
.join('');
|
|
58
|
-
|
|
59
|
-
return s.replace(/\n/g, `\n${padding}`);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const jsToEdn = function (js) {
|
|
63
|
-
switch (jsType(js)) {
|
|
64
|
-
case 'string':
|
|
65
|
-
return `"${js.replace(/"/g, '\\"')}"`;
|
|
66
|
-
case 'file':
|
|
67
|
-
return js.toString();
|
|
68
|
-
case 'keyword':
|
|
69
|
-
return js.toString();
|
|
70
|
-
case 'null':
|
|
71
|
-
return 'nil';
|
|
72
|
-
case 'regexp':
|
|
73
|
-
return `#"${js.source}"`;
|
|
74
|
-
|
|
75
|
-
// simple vertical format
|
|
76
|
-
case 'object': {
|
|
77
|
-
const obj = Object.keys(js)
|
|
78
|
-
.reduce(function (acc, key) {
|
|
79
|
-
const val = padBlock(key.length + 2, jsToEdn(js[key]));
|
|
80
|
-
return `${acc}:${key} ${val}\n `;
|
|
81
|
-
}, '')
|
|
82
|
-
.trim();
|
|
83
|
-
return `{${padBlock(1, obj)}}`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// simple horizontal format
|
|
87
|
-
case 'array': {
|
|
88
|
-
const arr = js
|
|
89
|
-
.reduce(function (acc, val) {
|
|
90
|
-
return `${acc} ${jsToEdn(val)}`;
|
|
91
|
-
}, '')
|
|
92
|
-
.trim();
|
|
93
|
-
return `[${padBlock(1, arr)}]`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 'number' 'boolean'
|
|
97
|
-
default:
|
|
98
|
-
return js.toString();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
module.exports = function (source, options) {
|
|
103
|
-
const code = new CodeBuilder(options);
|
|
104
|
-
const methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
105
|
-
|
|
106
|
-
if (methods.indexOf(source.method.toLowerCase()) === -1) {
|
|
107
|
-
return code.push('Method not supported').join();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const params = {
|
|
111
|
-
headers: source.allHeaders,
|
|
112
|
-
'query-params': source.queryObj,
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
// eslint-disable-next-line default-case
|
|
116
|
-
switch (source.postData.mimeType) {
|
|
117
|
-
case 'application/json':
|
|
118
|
-
params['content-type'] = new Keyword('json');
|
|
119
|
-
params['form-params'] = source.postData.jsonObj;
|
|
120
|
-
delete params.headers[helpers.getHeaderName(params.headers, 'content-type')];
|
|
121
|
-
break;
|
|
122
|
-
case 'application/x-www-form-urlencoded':
|
|
123
|
-
params['form-params'] = source.postData.paramsObj;
|
|
124
|
-
delete params.headers[helpers.getHeaderName(params.headers, 'content-type')];
|
|
125
|
-
break;
|
|
126
|
-
case 'text/plain':
|
|
127
|
-
params.body = source.postData.text;
|
|
128
|
-
delete params.headers[helpers.getHeaderName(params.headers, 'content-type')];
|
|
129
|
-
break;
|
|
130
|
-
case 'multipart/form-data':
|
|
131
|
-
if (source.postData.params) {
|
|
132
|
-
params.multipart = source.postData.params.map(function (x) {
|
|
133
|
-
if (x.fileName && !x.value) {
|
|
134
|
-
return {
|
|
135
|
-
name: x.name,
|
|
136
|
-
content: new File(x.fileName),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return {
|
|
141
|
-
name: x.name,
|
|
142
|
-
content: x.value,
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
delete params.headers[helpers.getHeaderName(params.headers, 'content-type')];
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (helpers.getHeader(params.headers, 'accept') === 'application/json') {
|
|
151
|
-
params.accept = new Keyword('json');
|
|
152
|
-
delete params.headers[helpers.getHeaderName(params.headers, 'accept')];
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
code.push("(require '[clj-http.client :as client])\n");
|
|
156
|
-
|
|
157
|
-
if (objEmpty(filterEmpty(params))) {
|
|
158
|
-
code.push('(client/%s "%s")', source.method.toLowerCase(), source.url);
|
|
159
|
-
} else {
|
|
160
|
-
code.push(
|
|
161
|
-
'(client/%s "%s" %s)',
|
|
162
|
-
source.method.toLowerCase(),
|
|
163
|
-
source.url,
|
|
164
|
-
padBlock(11 + source.method.length + source.url.length, jsToEdn(filterEmpty(params)))
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return code.join();
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
module.exports.info = {
|
|
172
|
-
key: 'clj_http',
|
|
173
|
-
title: 'clj-http',
|
|
174
|
-
link: 'https://github.com/dakrone/clj-http',
|
|
175
|
-
description: 'An idiomatic clojure http client wrapping the apache client.',
|
|
176
|
-
};
|