@scalar/snippetz 0.2.19 → 0.3.0
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/dist/clients.js +153 -155
- package/dist/clients.js.map +7 -0
- package/dist/httpsnippet-lite/esm/helpers/code-builder.js +44 -59
- package/dist/httpsnippet-lite/esm/helpers/code-builder.js.map +7 -0
- package/dist/httpsnippet-lite/esm/helpers/escape.js +41 -69
- package/dist/httpsnippet-lite/esm/helpers/escape.js.map +7 -0
- package/dist/httpsnippet-lite/esm/helpers/form-data.js +59 -0
- package/dist/httpsnippet-lite/esm/helpers/form-data.js.map +7 -0
- package/dist/httpsnippet-lite/esm/helpers/headers.js +23 -18
- package/dist/httpsnippet-lite/esm/helpers/headers.js.map +7 -0
- package/dist/httpsnippet-lite/esm/helpers/reducer.js +20 -0
- package/dist/httpsnippet-lite/esm/helpers/reducer.js.map +7 -0
- package/dist/httpsnippet-lite/esm/helpers/shell.js +13 -16
- package/dist/httpsnippet-lite/esm/helpers/shell.js.map +7 -0
- package/dist/httpsnippet-lite/esm/helpers/url.js +20 -0
- package/dist/httpsnippet-lite/esm/helpers/url.js.map +7 -0
- package/dist/httpsnippet-lite/esm/helpers/utils.js +16 -0
- package/dist/httpsnippet-lite/esm/helpers/utils.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js +72 -40
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/c/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/c/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/clojure/clj_http/client.js +149 -166
- package/dist/httpsnippet-lite/esm/targets/clojure/clj_http/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/clojure/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/clojure/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/httpclient/client.js +165 -161
- package/dist/httpsnippet-lite/esm/targets/csharp/httpclient/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/restsharp/client.js +47 -46
- package/dist/httpsnippet-lite/esm/targets/csharp/restsharp/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/target.js +18 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/go/native/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/go/native/client.js +167 -116
- package/dist/httpsnippet-lite/esm/targets/go/native/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/go/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/go/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/java/asynchttp/client.js +37 -44
- package/dist/httpsnippet-lite/esm/targets/java/asynchttp/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/java/nethttp/client.js +41 -43
- package/dist/httpsnippet-lite/esm/targets/java/nethttp/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js +75 -67
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/java/target.js +22 -0
- package/dist/httpsnippet-lite/esm/targets/java/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/java/unirest/client.js +37 -44
- package/dist/httpsnippet-lite/esm/targets/java/unirest/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/axios/client.js +79 -84
- package/dist/httpsnippet-lite/esm/targets/javascript/axios/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/jquery/client.js +76 -83
- package/dist/httpsnippet-lite/esm/targets/javascript/jquery/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/target.js +22 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/xhr/client.js +78 -79
- package/dist/httpsnippet-lite/esm/targets/javascript/xhr/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js +75 -67
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/kotlin/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/kotlin/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/node/axios/client.js +70 -77
- package/dist/httpsnippet-lite/esm/targets/node/axios/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/node/request/client.js +100 -0
- package/dist/httpsnippet-lite/esm/targets/node/request/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/node/target.js +24 -0
- package/dist/httpsnippet-lite/esm/targets/node/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/objc/helpers.js +36 -52
- package/dist/httpsnippet-lite/esm/targets/objc/helpers.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/objc/nsurlsession/client.js +157 -128
- package/dist/httpsnippet-lite/esm/targets/objc/nsurlsession/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/objc/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/objc/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/ocaml/cohttp/client.js +50 -65
- package/dist/httpsnippet-lite/esm/targets/ocaml/cohttp/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/ocaml/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/ocaml/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/php/helpers.js +72 -0
- package/dist/httpsnippet-lite/esm/targets/php/helpers.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/php/http1/client.js +85 -0
- package/dist/httpsnippet-lite/esm/targets/php/http1/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/php/http2/client.js +127 -0
- package/dist/httpsnippet-lite/esm/targets/php/http2/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/php/target.js +22 -0
- package/dist/httpsnippet-lite/esm/targets/php/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/common.js +61 -49
- package/dist/httpsnippet-lite/esm/targets/powershell/common.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/restmethod/client.js +12 -12
- package/dist/httpsnippet-lite/esm/targets/powershell/restmethod/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/target.js +18 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/webrequest/client.js +12 -12
- package/dist/httpsnippet-lite/esm/targets/powershell/webrequest/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/python/helpers.js +68 -0
- package/dist/httpsnippet-lite/esm/targets/python/helpers.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/python/python3/client.js +71 -90
- package/dist/httpsnippet-lite/esm/targets/python/python3/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/python/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/python/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/r/httr/client.js +99 -124
- package/dist/httpsnippet-lite/esm/targets/r/httr/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/r/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/r/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/ruby/native/client.js +69 -69
- package/dist/httpsnippet-lite/esm/targets/ruby/native/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/ruby/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/ruby/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js +106 -113
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/shell/target.js +20 -0
- package/dist/httpsnippet-lite/esm/targets/shell/target.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/shell/wget/client.js +42 -51
- package/dist/httpsnippet-lite/esm/targets/shell/wget/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/swift/helpers.js +51 -67
- package/dist/httpsnippet-lite/esm/targets/swift/helpers.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.js +132 -133
- package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.js.map +7 -0
- package/dist/httpsnippet-lite/esm/targets/swift/target.js +16 -0
- package/dist/httpsnippet-lite/esm/targets/swift/target.js.map +7 -0
- package/dist/httpsnippet-lite/types/helpers/code-builder.d.js +1 -0
- package/dist/httpsnippet-lite/types/helpers/code-builder.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/helpers/escape.d.js +1 -0
- package/dist/httpsnippet-lite/types/helpers/escape.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/helpers/form-data.d.js +28 -0
- package/dist/httpsnippet-lite/types/helpers/form-data.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/helpers/headers.d.js +1 -0
- package/dist/httpsnippet-lite/types/helpers/headers.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/helpers/reducer.d.js +1 -0
- package/dist/httpsnippet-lite/types/helpers/reducer.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/helpers/shell.d.js +1 -0
- package/dist/httpsnippet-lite/types/helpers/shell.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/helpers/url.d.js +1 -0
- package/dist/httpsnippet-lite/types/helpers/url.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/helpers/utils.d.js +1 -0
- package/dist/httpsnippet-lite/types/helpers/utils.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/httpsnippet.d.js +19 -0
- package/dist/httpsnippet-lite/types/httpsnippet.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/c/libcurl/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/c/libcurl/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/c/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/c/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/clojure/clj_http/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/clojure/clj_http/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/clojure/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/clojure/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/csharp/httpclient/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/csharp/httpclient/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/csharp/restsharp/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/csharp/restsharp/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/csharp/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/csharp/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/dart/http/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/dart/http/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/dart/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/dart/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/go/native/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/go/native/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/go/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/go/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/http/http1.1/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/http/http1.1/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/http/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/http/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/java/asynchttp/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/java/asynchttp/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/java/nethttp/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/java/nethttp/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/java/okhttp/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/java/okhttp/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/java/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/java/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/java/unirest/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/java/unirest/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/javascript/axios/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/javascript/axios/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/javascript/fetch/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/javascript/fetch/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/javascript/jquery/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/javascript/jquery/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/javascript/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/javascript/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/javascript/xhr/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/javascript/xhr/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/kotlin/okhttp/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/kotlin/okhttp/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/kotlin/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/kotlin/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/node/axios/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/node/axios/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/node/fetch/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/node/fetch/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/node/native/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/node/native/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/node/request/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/node/request/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/node/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/node/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/node/unirest/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/node/unirest/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/objc/helpers.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/objc/helpers.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/objc/nsurlsession/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/objc/nsurlsession/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/objc/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/objc/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/ocaml/cohttp/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/ocaml/cohttp/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/ocaml/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/ocaml/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/php/curl/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/php/curl/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/php/guzzle/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/php/guzzle/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/php/helpers.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/php/helpers.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/php/http1/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/php/http1/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/php/http2/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/php/http2/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/php/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/php/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/powershell/common.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/powershell/common.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/powershell/restmethod/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/powershell/restmethod/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/powershell/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/powershell/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/powershell/webrequest/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/powershell/webrequest/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/python/helpers.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/python/helpers.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/python/python3/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/python/python3/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/python/requests/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/python/requests/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/python/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/python/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/r/httr/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/r/httr/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/r/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/r/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/ruby/native/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/ruby/native/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/ruby/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/ruby/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/shell/curl/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/shell/curl/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/shell/httpie/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/shell/httpie/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/shell/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/shell/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/shell/wget/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/shell/wget/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/swift/helpers.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/swift/helpers.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/swift/nsurlsession/client.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/swift/nsurlsession/client.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/swift/target.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/swift/target.d.js.map +7 -0
- package/dist/httpsnippet-lite/types/targets/targets.d.js +1 -0
- package/dist/httpsnippet-lite/types/targets/targets.d.js.map +7 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +7 -0
- package/dist/plugins/c/libcurl/index.js +2 -1
- package/dist/plugins/c/libcurl/index.js.map +7 -0
- package/dist/plugins/c/libcurl/libcurl.js +12 -15
- package/dist/plugins/c/libcurl/libcurl.js.map +7 -0
- package/dist/plugins/c/libcurl/libcurl.test.js +208 -0
- package/dist/plugins/c/libcurl/libcurl.test.js.map +7 -0
- package/dist/plugins/clojure/clj_http/clj_http.js +12 -15
- package/dist/plugins/clojure/clj_http/clj_http.js.map +7 -0
- package/dist/plugins/clojure/clj_http/clj_http.test.js +151 -0
- package/dist/plugins/clojure/clj_http/clj_http.test.js.map +7 -0
- package/dist/plugins/clojure/clj_http/index.js +2 -1
- package/dist/plugins/clojure/clj_http/index.js.map +7 -0
- package/dist/plugins/csharp/httpclient/httpclient.js +12 -15
- package/dist/plugins/csharp/httpclient/httpclient.js.map +7 -0
- package/dist/plugins/csharp/httpclient/index.js +2 -1
- package/dist/plugins/csharp/httpclient/index.js.map +7 -0
- package/dist/plugins/csharp/restsharp/index.js +2 -1
- package/dist/plugins/csharp/restsharp/index.js.map +7 -0
- package/dist/plugins/csharp/restsharp/restsharp.js +12 -15
- package/dist/plugins/csharp/restsharp/restsharp.js.map +7 -0
- package/dist/plugins/dart/http/http.js +92 -96
- package/dist/plugins/dart/http/http.js.map +7 -0
- package/dist/plugins/dart/http/http.test.js +550 -0
- package/dist/plugins/dart/http/http.test.js.map +7 -0
- package/dist/plugins/dart/http/index.js +2 -1
- package/dist/plugins/dart/http/index.js.map +7 -0
- package/dist/plugins/go/native/index.js +2 -1
- package/dist/plugins/go/native/index.js.map +7 -0
- package/dist/plugins/go/native/native.js +12 -15
- package/dist/plugins/go/native/native.js.map +7 -0
- package/dist/plugins/go/native/native.test.js +366 -0
- package/dist/plugins/go/native/native.test.js.map +7 -0
- package/dist/plugins/http/http11/http11.js +84 -104
- package/dist/plugins/http/http11/http11.js.map +7 -0
- package/dist/plugins/http/http11/http11.test.js +175 -0
- package/dist/plugins/http/http11/http11.test.js.map +7 -0
- package/dist/plugins/http/http11/index.js +2 -1
- package/dist/plugins/http/http11/index.js.map +7 -0
- package/dist/plugins/java/asynchttp/asynchttp.js +12 -15
- package/dist/plugins/java/asynchttp/asynchttp.js.map +7 -0
- package/dist/plugins/java/asynchttp/index.js +2 -1
- package/dist/plugins/java/asynchttp/index.js.map +7 -0
- package/dist/plugins/java/nethttp/index.js +2 -1
- package/dist/plugins/java/nethttp/index.js.map +7 -0
- package/dist/plugins/java/nethttp/nethttp.js +12 -15
- package/dist/plugins/java/nethttp/nethttp.js.map +7 -0
- package/dist/plugins/java/okhttp/index.js +2 -1
- package/dist/plugins/java/okhttp/index.js.map +7 -0
- package/dist/plugins/java/okhttp/okhttp.js +12 -15
- package/dist/plugins/java/okhttp/okhttp.js.map +7 -0
- package/dist/plugins/java/okhttp/okhttp.test.js +164 -0
- package/dist/plugins/java/okhttp/okhttp.test.js.map +7 -0
- package/dist/plugins/java/unirest/index.js +2 -1
- package/dist/plugins/java/unirest/index.js.map +7 -0
- package/dist/plugins/java/unirest/unirest.js +12 -15
- package/dist/plugins/java/unirest/unirest.js.map +7 -0
- package/dist/plugins/js/axios/axios.js +12 -15
- package/dist/plugins/js/axios/axios.js.map +7 -0
- package/dist/plugins/js/axios/index.d.ts +1 -1
- package/dist/plugins/js/axios/index.d.ts.map +1 -1
- package/dist/plugins/js/axios/index.js +5 -1
- package/dist/plugins/js/axios/index.js.map +7 -0
- package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/js/fetch/fetch.js +67 -60
- package/dist/plugins/js/fetch/fetch.js.map +7 -0
- package/dist/plugins/js/fetch/fetch.test.js +214 -0
- package/dist/plugins/js/fetch/fetch.test.js.map +7 -0
- package/dist/plugins/js/fetch/index.d.ts +1 -1
- package/dist/plugins/js/fetch/index.d.ts.map +1 -1
- package/dist/plugins/js/fetch/index.js +5 -1
- package/dist/plugins/js/fetch/index.js.map +7 -0
- package/dist/plugins/js/jquery/index.js +2 -1
- package/dist/plugins/js/jquery/index.js.map +7 -0
- package/dist/plugins/js/jquery/jquery.js +12 -15
- package/dist/plugins/js/jquery/jquery.js.map +7 -0
- package/dist/plugins/js/ofetch/index.js +2 -1
- package/dist/plugins/js/ofetch/index.js.map +7 -0
- package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/js/ofetch/ofetch.js +44 -67
- package/dist/plugins/js/ofetch/ofetch.js.map +7 -0
- package/dist/plugins/js/ofetch/ofetch.test.js +126 -0
- package/dist/plugins/js/ofetch/ofetch.test.js.map +7 -0
- package/dist/plugins/js/xhr/index.js +2 -1
- package/dist/plugins/js/xhr/index.js.map +7 -0
- package/dist/plugins/js/xhr/xhr.js +12 -15
- package/dist/plugins/js/xhr/xhr.js.map +7 -0
- package/dist/plugins/kotlin/okhttp/index.js +2 -1
- package/dist/plugins/kotlin/okhttp/index.js.map +7 -0
- package/dist/plugins/kotlin/okhttp/okhttp.js +12 -15
- package/dist/plugins/kotlin/okhttp/okhttp.js.map +7 -0
- package/dist/plugins/kotlin/okhttp/okhttp.test.js +164 -0
- package/dist/plugins/kotlin/okhttp/okhttp.test.js.map +7 -0
- package/dist/plugins/node/axios/axios.js +12 -15
- package/dist/plugins/node/axios/axios.js.map +7 -0
- package/dist/plugins/node/axios/index.js +2 -1
- package/dist/plugins/node/axios/index.js.map +7 -0
- package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/node/fetch/fetch.js +73 -59
- package/dist/plugins/node/fetch/fetch.js.map +7 -0
- package/dist/plugins/node/fetch/fetch.test.js +200 -0
- package/dist/plugins/node/fetch/fetch.test.js.map +7 -0
- package/dist/plugins/node/fetch/index.js +2 -1
- package/dist/plugins/node/fetch/index.js.map +7 -0
- package/dist/plugins/node/ofetch/index.js +2 -1
- package/dist/plugins/node/ofetch/index.js.map +7 -0
- package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/ofetch/ofetch.js +44 -67
- package/dist/plugins/node/ofetch/ofetch.js.map +7 -0
- package/dist/plugins/node/ofetch/ofetch.test.js +126 -0
- package/dist/plugins/node/ofetch/ofetch.test.js.map +7 -0
- package/dist/plugins/node/undici/index.js +2 -1
- package/dist/plugins/node/undici/index.js.map +7 -0
- package/dist/plugins/node/undici/undici.d.ts.map +1 -1
- package/dist/plugins/node/undici/undici.js +46 -62
- package/dist/plugins/node/undici/undici.js.map +7 -0
- package/dist/plugins/node/undici/undici.test.js +133 -0
- package/dist/plugins/node/undici/undici.test.js.map +7 -0
- package/dist/plugins/objc/nsurlsession/index.js +2 -1
- package/dist/plugins/objc/nsurlsession/index.js.map +7 -0
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +12 -15
- package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +7 -0
- package/dist/plugins/ocaml/cohttp/cohttp.js +12 -15
- package/dist/plugins/ocaml/cohttp/cohttp.js.map +7 -0
- package/dist/plugins/ocaml/cohttp/index.js +2 -1
- package/dist/plugins/ocaml/cohttp/index.js.map +7 -0
- package/dist/plugins/php/curl/curl.js +119 -157
- package/dist/plugins/php/curl/curl.js.map +7 -0
- package/dist/plugins/php/curl/curl.test.js +564 -0
- package/dist/plugins/php/curl/curl.test.js.map +7 -0
- package/dist/plugins/php/curl/index.js +2 -1
- package/dist/plugins/php/curl/index.js.map +7 -0
- package/dist/plugins/php/guzzle/guzzle.js +115 -148
- package/dist/plugins/php/guzzle/guzzle.js.map +7 -0
- package/dist/plugins/php/guzzle/guzzle.test.js +546 -0
- package/dist/plugins/php/guzzle/guzzle.test.js.map +7 -0
- package/dist/plugins/php/guzzle/index.js +2 -1
- package/dist/plugins/php/guzzle/index.js.map +7 -0
- package/dist/plugins/powershell/restmethod/index.js +2 -1
- package/dist/plugins/powershell/restmethod/index.js.map +7 -0
- package/dist/plugins/powershell/restmethod/restmethod.js +12 -15
- package/dist/plugins/powershell/restmethod/restmethod.js.map +7 -0
- package/dist/plugins/powershell/webrequest/index.js +2 -1
- package/dist/plugins/powershell/webrequest/index.js.map +7 -0
- package/dist/plugins/powershell/webrequest/webrequest.js +12 -15
- package/dist/plugins/powershell/webrequest/webrequest.js.map +7 -0
- package/dist/plugins/python/python3/index.js +2 -1
- package/dist/plugins/python/python3/index.js.map +7 -0
- package/dist/plugins/python/python3/python3.js +12 -15
- package/dist/plugins/python/python3/python3.js.map +7 -0
- package/dist/plugins/python/requests/index.js +2 -1
- package/dist/plugins/python/requests/index.js.map +7 -0
- package/dist/plugins/python/requests/requests.d.ts.map +1 -1
- package/dist/plugins/python/requests/requests.js +98 -126
- package/dist/plugins/python/requests/requests.js.map +7 -0
- package/dist/plugins/python/requests/requests.test.js +419 -0
- package/dist/plugins/python/requests/requests.test.js.map +7 -0
- package/dist/plugins/r/httr/httr.js +12 -15
- package/dist/plugins/r/httr/httr.js.map +7 -0
- package/dist/plugins/r/httr/index.js +2 -1
- package/dist/plugins/r/httr/index.js.map +7 -0
- package/dist/plugins/ruby/native/index.js +2 -1
- package/dist/plugins/ruby/native/index.js.map +7 -0
- package/dist/plugins/ruby/native/native.js +12 -15
- package/dist/plugins/ruby/native/native.js.map +7 -0
- package/dist/plugins/ruby/native/native.test.js +240 -0
- package/dist/plugins/ruby/native/native.test.js.map +7 -0
- package/dist/plugins/shell/curl/curl.js +81 -114
- package/dist/plugins/shell/curl/curl.js.map +7 -0
- package/dist/plugins/shell/curl/curl.test.js +427 -0
- package/dist/plugins/shell/curl/curl.test.js.map +7 -0
- package/dist/plugins/shell/curl/index.js +2 -1
- package/dist/plugins/shell/curl/index.js.map +7 -0
- package/dist/plugins/shell/httpie/httpie.js +12 -15
- package/dist/plugins/shell/httpie/httpie.js.map +7 -0
- package/dist/plugins/shell/httpie/httpie.test.js +113 -0
- package/dist/plugins/shell/httpie/httpie.test.js.map +7 -0
- package/dist/plugins/shell/httpie/index.js +2 -1
- package/dist/plugins/shell/httpie/index.js.map +7 -0
- package/dist/plugins/shell/wget/index.js +2 -1
- package/dist/plugins/shell/wget/index.js.map +7 -0
- package/dist/plugins/shell/wget/wget.js +12 -15
- package/dist/plugins/shell/wget/wget.js.map +7 -0
- package/dist/plugins/shell/wget/wget.test.js +143 -0
- package/dist/plugins/shell/wget/wget.test.js.map +7 -0
- package/dist/plugins/swift/nsurlsession/index.js +2 -1
- package/dist/plugins/swift/nsurlsession/index.js.map +7 -0
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +12 -15
- package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +7 -0
- package/dist/plugins/swift/nsurlsession/nsurlsession.test.js +344 -0
- package/dist/plugins/swift/nsurlsession/nsurlsession.test.js.map +7 -0
- package/dist/snippetz.js +27 -27
- package/dist/snippetz.js.map +7 -0
- package/dist/snippetz.test.js +79 -0
- package/dist/snippetz.test.js.map +7 -0
- package/dist/utils/convertWithHttpSnippetLite.js +101 -104
- package/dist/utils/convertWithHttpSnippetLite.js.map +7 -0
- package/dist/utils/convertWithHttpSnippetLite.test.js +106 -0
- package/dist/utils/convertWithHttpSnippetLite.test.js.map +7 -0
- package/dist/utils/create-search-params.d.ts +4 -0
- package/dist/utils/create-search-params.d.ts.map +1 -0
- package/dist/utils/create-search-params.js +11 -0
- package/dist/utils/create-search-params.js.map +7 -0
- package/dist/utils/create-search-params.test.js +49 -0
- package/dist/utils/create-search-params.test.js.map +7 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -4
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/needsQuotes.js +5 -8
- package/dist/utils/needsQuotes.js.map +7 -0
- package/dist/utils/objectToString.d.ts +8 -0
- package/dist/utils/objectToString.d.ts.map +1 -1
- package/dist/utils/objectToString.js +48 -54
- package/dist/utils/objectToString.js.map +7 -0
- package/package.json +147 -151
- package/dist/utils/arrayToObject.d.ts +0 -8
- package/dist/utils/arrayToObject.d.ts.map +0 -1
- package/dist/utils/arrayToObject.js +0 -14
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { goNative } from "./native.js";
|
|
3
|
+
describe("goNative", () => {
|
|
4
|
+
it("returns a basic request", () => {
|
|
5
|
+
const result = goNative.generate({
|
|
6
|
+
url: "https://example.com"
|
|
7
|
+
});
|
|
8
|
+
expect(result).toBe(
|
|
9
|
+
`package main
|
|
10
|
+
|
|
11
|
+
import (
|
|
12
|
+
"fmt"
|
|
13
|
+
"io"
|
|
14
|
+
"net/http"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
func main() {
|
|
18
|
+
url := "https://example.com"
|
|
19
|
+
|
|
20
|
+
req, _ := http.NewRequest("GET", url, nil)
|
|
21
|
+
|
|
22
|
+
res, _ := http.DefaultClient.Do(req)
|
|
23
|
+
|
|
24
|
+
defer res.Body.Close()
|
|
25
|
+
body, _ := io.ReadAll(res.Body)
|
|
26
|
+
|
|
27
|
+
fmt.Println(res)
|
|
28
|
+
fmt.Println(string(body))
|
|
29
|
+
|
|
30
|
+
}`
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
it("returns a POST request", () => {
|
|
34
|
+
const result = goNative.generate({
|
|
35
|
+
url: "https://example.com",
|
|
36
|
+
method: "post"
|
|
37
|
+
});
|
|
38
|
+
expect(result).toBe(
|
|
39
|
+
`package main
|
|
40
|
+
|
|
41
|
+
import (
|
|
42
|
+
"fmt"
|
|
43
|
+
"io"
|
|
44
|
+
"net/http"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
func main() {
|
|
48
|
+
url := "https://example.com"
|
|
49
|
+
|
|
50
|
+
req, _ := http.NewRequest("POST", url, nil)
|
|
51
|
+
|
|
52
|
+
res, _ := http.DefaultClient.Do(req)
|
|
53
|
+
|
|
54
|
+
defer res.Body.Close()
|
|
55
|
+
body, _ := io.ReadAll(res.Body)
|
|
56
|
+
|
|
57
|
+
fmt.Println(res)
|
|
58
|
+
fmt.Println(string(body))
|
|
59
|
+
|
|
60
|
+
}`
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
it("has headers", () => {
|
|
64
|
+
const result = goNative.generate({
|
|
65
|
+
url: "https://example.com",
|
|
66
|
+
headers: [
|
|
67
|
+
{
|
|
68
|
+
name: "Content-Type",
|
|
69
|
+
value: "application/json"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
expect(result).toBe(
|
|
74
|
+
`package main
|
|
75
|
+
|
|
76
|
+
import (
|
|
77
|
+
"fmt"
|
|
78
|
+
"io"
|
|
79
|
+
"net/http"
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
func main() {
|
|
83
|
+
url := "https://example.com"
|
|
84
|
+
|
|
85
|
+
req, _ := http.NewRequest("GET", url, nil)
|
|
86
|
+
|
|
87
|
+
req.Header.Add("Content-Type", "application/json")
|
|
88
|
+
|
|
89
|
+
res, _ := http.DefaultClient.Do(req)
|
|
90
|
+
|
|
91
|
+
defer res.Body.Close()
|
|
92
|
+
body, _ := io.ReadAll(res.Body)
|
|
93
|
+
|
|
94
|
+
fmt.Println(res)
|
|
95
|
+
fmt.Println(string(body))
|
|
96
|
+
|
|
97
|
+
}`
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
it("handles multipart form data with files", () => {
|
|
101
|
+
const result = goNative.generate({
|
|
102
|
+
url: "https://example.com",
|
|
103
|
+
method: "POST",
|
|
104
|
+
postData: {
|
|
105
|
+
mimeType: "multipart/form-data",
|
|
106
|
+
params: [
|
|
107
|
+
{
|
|
108
|
+
name: "file",
|
|
109
|
+
fileName: "test.txt"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "field",
|
|
113
|
+
value: "value"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
expect(result).toBe(
|
|
119
|
+
`package main
|
|
120
|
+
|
|
121
|
+
import (
|
|
122
|
+
"bytes"
|
|
123
|
+
"fmt"
|
|
124
|
+
"io"
|
|
125
|
+
"mime/multipart"
|
|
126
|
+
"net/http"
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
func main() {
|
|
130
|
+
url := "https://example.com"
|
|
131
|
+
|
|
132
|
+
payload := &bytes.Buffer{}
|
|
133
|
+
writer := multipart.NewWriter(payload)
|
|
134
|
+
|
|
135
|
+
part, _ := writer.CreateFormFile("file", "test.txt")
|
|
136
|
+
|
|
137
|
+
f, _ := os.Open("test.txt")
|
|
138
|
+
defer f.Close()
|
|
139
|
+
|
|
140
|
+
_, _ = io.Copy(part, f)
|
|
141
|
+
|
|
142
|
+
_ = writer.WriteField("field", "value")
|
|
143
|
+
writer.Close()
|
|
144
|
+
|
|
145
|
+
req, _ := http.NewRequest("POST", url, payload)
|
|
146
|
+
|
|
147
|
+
req.Header.Set("Content-Type", writer.FormDataContentType())
|
|
148
|
+
res, _ := http.DefaultClient.Do(req)
|
|
149
|
+
|
|
150
|
+
defer res.Body.Close()
|
|
151
|
+
body, _ := io.ReadAll(res.Body)
|
|
152
|
+
|
|
153
|
+
fmt.Println(res)
|
|
154
|
+
fmt.Println(string(body))
|
|
155
|
+
|
|
156
|
+
}`
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
it("handles url-encoded form data with special characters", () => {
|
|
160
|
+
const result = goNative.generate({
|
|
161
|
+
url: "https://example.com",
|
|
162
|
+
method: "POST",
|
|
163
|
+
postData: {
|
|
164
|
+
mimeType: "application/x-www-form-urlencoded",
|
|
165
|
+
params: [
|
|
166
|
+
{
|
|
167
|
+
name: "special chars!@#",
|
|
168
|
+
value: "value"
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
expect(result).toBe(
|
|
174
|
+
`package main
|
|
175
|
+
|
|
176
|
+
import (
|
|
177
|
+
"fmt"
|
|
178
|
+
"io"
|
|
179
|
+
"net/http"
|
|
180
|
+
"net/url"
|
|
181
|
+
"strings"
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
func main() {
|
|
185
|
+
url := "https://example.com"
|
|
186
|
+
|
|
187
|
+
postData := url.Values{}
|
|
188
|
+
postData.Set("special chars!@#", "value")
|
|
189
|
+
|
|
190
|
+
req, _ := http.NewRequest("POST", url, strings.NewReader(postData.Encode()))
|
|
191
|
+
|
|
192
|
+
res, _ := http.DefaultClient.Do(req)
|
|
193
|
+
|
|
194
|
+
defer res.Body.Close()
|
|
195
|
+
body, _ := io.ReadAll(res.Body)
|
|
196
|
+
|
|
197
|
+
fmt.Println(res)
|
|
198
|
+
fmt.Println(string(body))
|
|
199
|
+
|
|
200
|
+
}`
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
it("handles binary data", () => {
|
|
204
|
+
const result = goNative.generate({
|
|
205
|
+
url: "https://example.com",
|
|
206
|
+
method: "POST",
|
|
207
|
+
postData: {
|
|
208
|
+
mimeType: "application/octet-stream",
|
|
209
|
+
text: "binary content"
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
expect(result).toBe(
|
|
213
|
+
`package main
|
|
214
|
+
|
|
215
|
+
import (
|
|
216
|
+
"fmt"
|
|
217
|
+
"io"
|
|
218
|
+
"net/http"
|
|
219
|
+
"strings"
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
func main() {
|
|
223
|
+
url := "https://example.com"
|
|
224
|
+
|
|
225
|
+
payload := strings.NewReader("binary content")
|
|
226
|
+
|
|
227
|
+
req, _ := http.NewRequest("POST", url, payload)
|
|
228
|
+
|
|
229
|
+
res, _ := http.DefaultClient.Do(req)
|
|
230
|
+
|
|
231
|
+
defer res.Body.Close()
|
|
232
|
+
body, _ := io.ReadAll(res.Body)
|
|
233
|
+
|
|
234
|
+
fmt.Println(res)
|
|
235
|
+
fmt.Println(string(body))
|
|
236
|
+
|
|
237
|
+
}`
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
it("handles special characters in URL", () => {
|
|
241
|
+
const result = goNative.generate({
|
|
242
|
+
url: "https://example.com/path with spaces/[brackets]"
|
|
243
|
+
});
|
|
244
|
+
expect(result).toBe(
|
|
245
|
+
`package main
|
|
246
|
+
|
|
247
|
+
import (
|
|
248
|
+
"fmt"
|
|
249
|
+
"io"
|
|
250
|
+
"net/http"
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
func main() {
|
|
254
|
+
url := "https://example.com/path%20with%20spaces/[brackets]"
|
|
255
|
+
|
|
256
|
+
req, _ := http.NewRequest("GET", url, nil)
|
|
257
|
+
|
|
258
|
+
res, _ := http.DefaultClient.Do(req)
|
|
259
|
+
|
|
260
|
+
defer res.Body.Close()
|
|
261
|
+
body, _ := io.ReadAll(res.Body)
|
|
262
|
+
|
|
263
|
+
fmt.Println(res)
|
|
264
|
+
fmt.Println(string(body))
|
|
265
|
+
|
|
266
|
+
}`
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
it("handles multiple headers with same name", () => {
|
|
270
|
+
const result = goNative.generate({
|
|
271
|
+
url: "https://example.com",
|
|
272
|
+
headers: [
|
|
273
|
+
{ name: "X-Custom", value: "value1" },
|
|
274
|
+
{ name: "X-Custom", value: "value2" }
|
|
275
|
+
]
|
|
276
|
+
});
|
|
277
|
+
expect(result).toBe(
|
|
278
|
+
`package main
|
|
279
|
+
|
|
280
|
+
import (
|
|
281
|
+
"fmt"
|
|
282
|
+
"io"
|
|
283
|
+
"net/http"
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
func main() {
|
|
287
|
+
url := "https://example.com"
|
|
288
|
+
|
|
289
|
+
req, _ := http.NewRequest("GET", url, nil)
|
|
290
|
+
|
|
291
|
+
req.Header.Add("X-Custom", "value2")
|
|
292
|
+
|
|
293
|
+
res, _ := http.DefaultClient.Do(req)
|
|
294
|
+
|
|
295
|
+
defer res.Body.Close()
|
|
296
|
+
body, _ := io.ReadAll(res.Body)
|
|
297
|
+
|
|
298
|
+
fmt.Println(res)
|
|
299
|
+
fmt.Println(string(body))
|
|
300
|
+
|
|
301
|
+
}`
|
|
302
|
+
);
|
|
303
|
+
});
|
|
304
|
+
it("handles headers with empty values", () => {
|
|
305
|
+
const result = goNative.generate({
|
|
306
|
+
url: "https://example.com",
|
|
307
|
+
headers: [{ name: "X-Empty", value: "" }]
|
|
308
|
+
});
|
|
309
|
+
expect(result).toBe(
|
|
310
|
+
`package main
|
|
311
|
+
|
|
312
|
+
import (
|
|
313
|
+
"fmt"
|
|
314
|
+
"io"
|
|
315
|
+
"net/http"
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
func main() {
|
|
319
|
+
url := "https://example.com"
|
|
320
|
+
|
|
321
|
+
req, _ := http.NewRequest("GET", url, nil)
|
|
322
|
+
|
|
323
|
+
req.Header.Add("X-Empty", "")
|
|
324
|
+
|
|
325
|
+
res, _ := http.DefaultClient.Do(req)
|
|
326
|
+
|
|
327
|
+
defer res.Body.Close()
|
|
328
|
+
body, _ := io.ReadAll(res.Body)
|
|
329
|
+
|
|
330
|
+
fmt.Println(res)
|
|
331
|
+
fmt.Println(string(body))
|
|
332
|
+
|
|
333
|
+
}`
|
|
334
|
+
);
|
|
335
|
+
});
|
|
336
|
+
it("handles query string parameters", () => {
|
|
337
|
+
const result = goNative.generate({
|
|
338
|
+
url: "https://example.com/api?param1=value1¶m2=special value¶m3=123"
|
|
339
|
+
});
|
|
340
|
+
expect(result).toBe(
|
|
341
|
+
`package main
|
|
342
|
+
|
|
343
|
+
import (
|
|
344
|
+
"fmt"
|
|
345
|
+
"io"
|
|
346
|
+
"net/http"
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
func main() {
|
|
350
|
+
url := "https://example.com/api?param1=value1¶m2=special%20value¶m3=123"
|
|
351
|
+
|
|
352
|
+
req, _ := http.NewRequest("GET", url, nil)
|
|
353
|
+
|
|
354
|
+
res, _ := http.DefaultClient.Do(req)
|
|
355
|
+
|
|
356
|
+
defer res.Body.Close()
|
|
357
|
+
body, _ := io.ReadAll(res.Body)
|
|
358
|
+
|
|
359
|
+
fmt.Println(res)
|
|
360
|
+
fmt.Println(string(body))
|
|
361
|
+
|
|
362
|
+
}`
|
|
363
|
+
);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
//# sourceMappingURL=native.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/plugins/go/native/native.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { goNative } from './native'\n\ndescribe('goNative', () => {\n it('returns a basic request', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n)\n\nfunc main() {\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('returns a POST request', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n method: 'post',\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n)\n\nfunc main() {\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"POST\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('has headers', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n })\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n)\n\nfunc main() {\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"Content-Type\", \"application/json\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles multipart form data with files', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n method: 'POST',\n postData: {\n mimeType: 'multipart/form-data',\n params: [\n {\n name: 'file',\n fileName: 'test.txt',\n },\n {\n name: 'field',\n value: 'value',\n },\n ],\n },\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"mime/multipart\"\n\t\"net/http\"\n)\n\nfunc main() {\n\turl := \"https://example.com\"\n\n\tpayload := &bytes.Buffer{}\n\twriter := multipart.NewWriter(payload)\n\n\tpart, _ := writer.CreateFormFile(\"file\", \"test.txt\")\n\n\tf, _ := os.Open(\"test.txt\")\n\tdefer f.Close()\n\n\t_, _ = io.Copy(part, f)\n\n\t_ = writer.WriteField(\"field\", \"value\")\n\twriter.Close()\n\n\treq, _ := http.NewRequest(\"POST\", url, payload)\n\n\treq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles url-encoded form data with special characters', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n method: 'POST',\n postData: {\n mimeType: 'application/x-www-form-urlencoded',\n params: [\n {\n name: 'special chars!@#',\n value: 'value',\n },\n ],\n },\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"net/url\"\n\t\"strings\"\n)\n\nfunc main() {\n\turl := \"https://example.com\"\n\n\tpostData := url.Values{}\n\tpostData.Set(\"special chars!@#\", \"value\")\n\n\treq, _ := http.NewRequest(\"POST\", url, strings.NewReader(postData.Encode()))\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles binary data', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n method: 'POST',\n postData: {\n mimeType: 'application/octet-stream',\n text: 'binary content',\n },\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"strings\"\n)\n\nfunc main() {\n\turl := \"https://example.com\"\n\n\tpayload := strings.NewReader(\"binary content\")\n\n\treq, _ := http.NewRequest(\"POST\", url, payload)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles special characters in URL', () => {\n const result = goNative.generate({\n url: 'https://example.com/path with spaces/[brackets]',\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n)\n\nfunc main() {\n\turl := \"https://example.com/path%20with%20spaces/[brackets]\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles multiple headers with same name', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n headers: [\n { name: 'X-Custom', value: 'value1' },\n { name: 'X-Custom', value: 'value2' },\n ],\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n)\n\nfunc main() {\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"X-Custom\", \"value2\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles headers with empty values', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n headers: [{ name: 'X-Empty', value: '' }],\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n)\n\nfunc main() {\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"X-Empty\", \"\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles query string parameters', () => {\n const result = goNative.generate({\n url: 'https://example.com/api?param1=value1¶m2=special value¶m3=123',\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n)\n\nfunc main() {\n\turl := \"https://example.com/api?param1=value1¶m2=special%20value¶m3=123\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,gBAAgB;AAEzB,SAAS,YAAY,MAAM;AACzB,KAAG,2BAA2B,MAAM;AAClC,UAAM,SAAS,SAAS,SAAS;AAAA,MAC/B,KAAK;AAAA,IACP,CAAC;AAED,WAAO,MAAM,EAAE;AAAA,MACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAsBF;AAAA,EACF,CAAC;AAED,KAAG,0BAA0B,MAAM;AACjC,UAAM,SAAS,SAAS,SAAS;AAAA,MAC/B,KAAK;AAAA,MACL,QAAQ;AAAA,IACV,CAAC;AAED,WAAO,MAAM,EAAE;AAAA,MACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAsBF;AAAA,EACF,CAAC;AAED,KAAG,eAAe,MAAM;AACtB,UAAM,SAAS,SAAS,SA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44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
body =
|
|
86
|
-
normalizedRequest.postData.params
|
|
87
|
-
.map((param) => {
|
|
88
|
-
if (param.fileName) {
|
|
89
|
-
return `--${boundary}\r\nContent-Disposition: form-data; name="${param.name}"; filename="${param.fileName}"\r\n\r\n`;
|
|
90
|
-
}
|
|
91
|
-
return `--${boundary}\r\nContent-Disposition: form-data; name="${param.name}"\r\n\r\n${param.value}\r\n`;
|
|
92
|
-
})
|
|
93
|
-
.join('') + `--${boundary}--\r\n`;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// Add headers to requestString
|
|
97
|
-
headers.forEach((value, name) => {
|
|
98
|
-
requestString += `${name}: ${value}\r\n`;
|
|
99
|
-
});
|
|
100
|
-
// Add body to requestString
|
|
101
|
-
requestString += `\r\n${body}`;
|
|
102
|
-
return requestString;
|
|
103
|
-
},
|
|
2
|
+
target: "http",
|
|
3
|
+
client: "http1.1",
|
|
4
|
+
title: "HTTP/1.1",
|
|
5
|
+
generate(request) {
|
|
6
|
+
const normalizedRequest = {
|
|
7
|
+
method: "GET",
|
|
8
|
+
headers: [],
|
|
9
|
+
queryString: [],
|
|
10
|
+
...request
|
|
11
|
+
};
|
|
12
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
13
|
+
let url;
|
|
14
|
+
let path;
|
|
15
|
+
try {
|
|
16
|
+
url = new URL(normalizedRequest.url || "http://");
|
|
17
|
+
path = url.pathname + (url.search || "");
|
|
18
|
+
} catch (_error) {
|
|
19
|
+
path = normalizedRequest.url || "/";
|
|
20
|
+
}
|
|
21
|
+
const hostname = url?.hostname || "UNKNOWN_HOSTNAME";
|
|
22
|
+
let requestString = `${normalizedRequest.method} ${path} HTTP/1.1\r
|
|
23
|
+
`;
|
|
24
|
+
if (normalizedRequest.queryString.length) {
|
|
25
|
+
const queryString = normalizedRequest.queryString.map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`).join("&");
|
|
26
|
+
requestString = `${normalizedRequest.method} ${path}?${queryString} HTTP/1.1\r
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
const headers = /* @__PURE__ */ new Map();
|
|
30
|
+
headers.set("Host", hostname);
|
|
31
|
+
normalizedRequest.headers.forEach((header) => {
|
|
32
|
+
if (headers.has(header.name)) {
|
|
33
|
+
headers.set(header.name, `${headers.get(header.name)}, ${header.value}`);
|
|
34
|
+
} else {
|
|
35
|
+
headers.set(header.name, header.value);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (normalizedRequest.queryString.length) {
|
|
39
|
+
const queryString = normalizedRequest.queryString.map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`).join("&");
|
|
40
|
+
requestString = `${normalizedRequest.method} ${path}?${queryString} HTTP/1.1\r
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
let body = "";
|
|
44
|
+
if (normalizedRequest.postData) {
|
|
45
|
+
if (normalizedRequest.postData.mimeType === "application/json" && normalizedRequest.postData.text) {
|
|
46
|
+
headers.set("Content-Type", "application/json");
|
|
47
|
+
body = normalizedRequest.postData.text;
|
|
48
|
+
} else if (normalizedRequest.postData.mimeType === "application/octet-stream" && normalizedRequest.postData.text) {
|
|
49
|
+
headers.set("Content-Type", "application/octet-stream");
|
|
50
|
+
body = normalizedRequest.postData.text;
|
|
51
|
+
} else if (normalizedRequest.postData.mimeType === "application/x-www-form-urlencoded" && normalizedRequest.postData.params) {
|
|
52
|
+
const formData = normalizedRequest.postData.params.map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value ?? "")}`).join("&");
|
|
53
|
+
headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
54
|
+
body = formData;
|
|
55
|
+
} else if (normalizedRequest.postData.mimeType === "multipart/form-data" && normalizedRequest.postData.params) {
|
|
56
|
+
const boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW";
|
|
57
|
+
headers.set("Content-Type", `multipart/form-data; boundary=${boundary}`);
|
|
58
|
+
body = normalizedRequest.postData.params.map((param) => {
|
|
59
|
+
if (param.fileName) {
|
|
60
|
+
return `--${boundary}\r
|
|
61
|
+
Content-Disposition: form-data; name="${param.name}"; filename="${param.fileName}"\r
|
|
62
|
+
\r
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
return `--${boundary}\r
|
|
66
|
+
Content-Disposition: form-data; name="${param.name}"\r
|
|
67
|
+
\r
|
|
68
|
+
${param.value}\r
|
|
69
|
+
`;
|
|
70
|
+
}).join("") + `--${boundary}--\r
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
headers.forEach((value, name) => {
|
|
75
|
+
requestString += `${name}: ${value}\r
|
|
76
|
+
`;
|
|
77
|
+
});
|
|
78
|
+
requestString += `\r
|
|
79
|
+
${body}`;
|
|
80
|
+
return requestString;
|
|
81
|
+
}
|
|
104
82
|
};
|
|
105
|
-
|
|
106
|
-
|
|
83
|
+
export {
|
|
84
|
+
httpHttp11
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=http11.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/plugins/http/http11/http11.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\n\n/**\n * http/http1.1\n */\nexport const httpHttp11: Plugin = {\n target: 'http',\n client: 'http1.1',\n title: 'HTTP/1.1',\n generate(request) {\n // Defaults\n const normalizedRequest = {\n method: 'GET',\n headers: [],\n queryString: [],\n ...request,\n }\n\n // Normalize method\n normalizedRequest.method = normalizedRequest.method.toUpperCase()\n\n // Parse URL with error handling\n let url\n let path\n try {\n url = new URL(normalizedRequest.url || 'http://')\n path = url.pathname + (url.search || '')\n } catch (_error) {\n // Oops, got an invalid URL, use the provided URL directly.\n path = normalizedRequest.url || '/'\n }\n\n const hostname = url?.hostname || 'UNKNOWN_HOSTNAME'\n\n // Start building the request\n let requestString = `${normalizedRequest.method} ${path} HTTP/1.1\\r\\n`\n\n // Handle query string parameters\n if (normalizedRequest.queryString.length) {\n const queryString = normalizedRequest.queryString\n .map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`)\n .join('&')\n\n // Append query string to the path\n requestString = `${normalizedRequest.method} ${path}?${queryString} HTTP/1.1\\r\\n`\n }\n\n // Store all headers\n const headers = new Map()\n\n // Host header\n headers.set('Host', hostname)\n\n // Passed headers\n normalizedRequest.headers.forEach((header) => {\n if (headers.has(header.name)) {\n headers.set(header.name, `${headers.get(header.name)}, ${header.value}`)\n } else {\n headers.set(header.name, header.value)\n }\n })\n\n // Query string parameters\n if (normalizedRequest.queryString.length) {\n const queryString = normalizedRequest.queryString\n .map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`)\n .join('&')\n\n // Append query string to the path\n requestString = `${normalizedRequest.method} ${path}?${queryString} HTTP/1.1\\r\\n`\n }\n\n // Request body\n let body = ''\n if (normalizedRequest.postData) {\n // Always set the Content-Type header based on postData.mimeType\n if (normalizedRequest.postData.mimeType === 'application/json' && normalizedRequest.postData.text) {\n headers.set('Content-Type', 'application/json')\n body = normalizedRequest.postData.text\n } else if (\n normalizedRequest.postData.mimeType === 'application/octet-stream' &&\n normalizedRequest.postData.text\n ) {\n headers.set('Content-Type', 'application/octet-stream')\n body = normalizedRequest.postData.text\n } else if (\n normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&\n normalizedRequest.postData.params\n ) {\n const formData = normalizedRequest.postData.params\n .map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value ?? '')}`)\n .join('&')\n\n headers.set('Content-Type', 'application/x-www-form-urlencoded')\n body = formData\n } else if (normalizedRequest.postData.mimeType === 'multipart/form-data' && normalizedRequest.postData.params) {\n const boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW'\n headers.set('Content-Type', `multipart/form-data; boundary=${boundary}`)\n\n body =\n normalizedRequest.postData.params\n .map((param) => {\n if (param.fileName) {\n return `--${boundary}\\r\\nContent-Disposition: form-data; name=\"${param.name}\"; filename=\"${param.fileName}\"\\r\\n\\r\\n`\n }\n return `--${boundary}\\r\\nContent-Disposition: form-data; name=\"${param.name}\"\\r\\n\\r\\n${param.value}\\r\\n`\n })\n .join('') + `--${boundary}--\\r\\n`\n }\n }\n\n // Add headers to requestString\n headers.forEach((value, name) => {\n requestString += `${name}: ${value}\\r\\n`\n })\n\n // Add body to requestString\n requestString += `\\r\\n${body}`\n\n return requestString\n },\n}\n"],
|
|
5
|
+
"mappings": "AAKO,MAAM,aAAqB;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS;AAEhB,UAAM,oBAAoB;AAAA,MACxB,QAAQ;AAAA,MACR,SAAS,CAAC;AAAA,MACV,aAAa,CAAC;AAAA,MACd,GAAG;AAAA,IACL;AAGA,sBAAkB,SAAS,kBAAkB,OAAO,YAAY;AAGhE,QAAI;AACJ,QAAI;AACJ,QAAI;AACF,YAAM,IAAI,IAAI,kBAAkB,OAAO,SAAS;AAChD,aAAO,IAAI,YAAY,IAAI,UAAU;AAAA,IACvC,SAAS,QAAQ;AAEf,a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