@readme/httpsnippet 3.1.2 → 4.0.1

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.
Files changed (839) hide show
  1. package/README.md +63 -62
  2. package/package.json +25 -19
  3. package/src/fixtures/customTarget.ts +14 -0
  4. package/src/fixtures/files/hello.txt +1 -0
  5. package/src/fixtures/mimetypes.ts +84 -0
  6. package/src/fixtures/requests/application-form-encoded.js +68 -0
  7. package/src/fixtures/requests/application-json.js +71 -0
  8. package/src/fixtures/requests/cookies.js +50 -0
  9. package/src/fixtures/requests/custom-method.js +40 -0
  10. package/src/fixtures/requests/full.js +98 -0
  11. package/src/fixtures/requests/headers.js +55 -0
  12. package/src/fixtures/requests/http-insecure.js +44 -0
  13. package/src/fixtures/requests/jsonObj-multiline.js +58 -0
  14. package/src/fixtures/requests/jsonObj-null-value.js +65 -0
  15. package/src/fixtures/requests/multipart-data.js +71 -0
  16. package/src/fixtures/requests/multipart-file.js +64 -0
  17. package/src/fixtures/requests/multipart-form-data-no-params.js +55 -0
  18. package/src/fixtures/requests/multipart-form-data.js +63 -0
  19. package/src/fixtures/requests/nested.js +63 -0
  20. package/src/fixtures/requests/query-encoded.js +58 -0
  21. package/src/fixtures/requests/query.js +63 -0
  22. package/src/fixtures/requests/short.js +44 -0
  23. package/src/fixtures/requests/text-plain.js +56 -0
  24. package/src/fixtures/runCustomFixtures.ts +47 -0
  25. package/src/helpers/__snapshots__/utils.test.ts.snap +364 -0
  26. package/src/helpers/code-builder.test.ts +42 -0
  27. package/src/helpers/code-builder.ts +85 -0
  28. package/src/helpers/{form-data.js → form-data.ts} +13 -44
  29. package/src/helpers/har-validator.ts +35 -0
  30. package/src/helpers/headers.test.ts +35 -0
  31. package/src/helpers/headers.ts +31 -0
  32. package/src/helpers/reducer.test.ts +27 -0
  33. package/src/helpers/reducer.ts +19 -0
  34. package/src/helpers/shell.ts +18 -0
  35. package/src/helpers/utils.test.ts +19 -0
  36. package/src/helpers/utils.ts +16 -0
  37. package/src/index.test.ts +221 -0
  38. package/src/index.ts +361 -0
  39. package/src/integration.test.ts +270 -0
  40. package/src/targets/c/libcurl/client.ts +50 -0
  41. package/src/targets/c/libcurl/fixtures/application-form-encoded.c +12 -0
  42. package/src/targets/c/libcurl/fixtures/application-json.c +12 -0
  43. package/src/targets/c/libcurl/fixtures/cookies.c +8 -0
  44. package/src/targets/c/libcurl/fixtures/custom-method.c +6 -0
  45. package/src/targets/c/libcurl/fixtures/full.c +15 -0
  46. package/src/targets/c/libcurl/fixtures/headers.c +12 -0
  47. package/src/targets/c/libcurl/fixtures/http-insecure.c +6 -0
  48. package/src/targets/c/libcurl/fixtures/jsonObj-multiline.c +12 -0
  49. package/src/targets/c/libcurl/fixtures/jsonObj-null-value.c +12 -0
  50. package/src/targets/c/libcurl/fixtures/multipart-data.c +12 -0
  51. package/src/targets/c/libcurl/fixtures/multipart-file.c +12 -0
  52. package/src/targets/c/libcurl/fixtures/multipart-form-data-no-params.c +10 -0
  53. package/src/targets/c/libcurl/fixtures/multipart-form-data.c +12 -0
  54. package/src/targets/c/libcurl/fixtures/nested.c +6 -0
  55. package/src/targets/c/libcurl/fixtures/query-encoded.c +6 -0
  56. package/src/targets/c/libcurl/fixtures/query.c +6 -0
  57. package/src/targets/c/libcurl/fixtures/short.c +6 -0
  58. package/src/targets/c/libcurl/fixtures/text-plain.c +12 -0
  59. package/src/targets/c/target.ts +14 -0
  60. package/src/targets/clojure/clj_http/client.ts +210 -0
  61. package/src/targets/clojure/clj_http/fixtures/application-form-encoded.clj +4 -0
  62. package/src/targets/clojure/clj_http/fixtures/application-json.clj +9 -0
  63. package/src/targets/clojure/clj_http/fixtures/cookies.clj +3 -0
  64. package/src/targets/clojure/clj_http/fixtures/custom-method.clj +1 -0
  65. package/src/targets/clojure/clj_http/fixtures/full.clj +8 -0
  66. package/src/targets/clojure/clj_http/fixtures/headers.clj +5 -0
  67. package/src/targets/clojure/clj_http/fixtures/http-insecure.clj +3 -0
  68. package/src/targets/clojure/clj_http/fixtures/jsonObj-multiline.clj +4 -0
  69. package/src/targets/clojure/clj_http/fixtures/jsonObj-null-value.clj +4 -0
  70. package/src/targets/clojure/clj_http/fixtures/multipart-data.clj +5 -0
  71. package/src/targets/clojure/clj_http/fixtures/multipart-file.clj +4 -0
  72. package/src/targets/clojure/clj_http/fixtures/multipart-form-data-no-params.clj +3 -0
  73. package/src/targets/clojure/clj_http/fixtures/multipart-form-data.clj +4 -0
  74. package/src/targets/clojure/clj_http/fixtures/nested.clj +5 -0
  75. package/src/targets/clojure/clj_http/fixtures/query-encoded.clj +4 -0
  76. package/src/targets/clojure/clj_http/fixtures/query.clj +5 -0
  77. package/src/targets/clojure/clj_http/fixtures/short.clj +3 -0
  78. package/src/targets/clojure/clj_http/fixtures/text-plain.clj +3 -0
  79. package/src/targets/clojure/target.ts +14 -0
  80. package/src/targets/csharp/httpclient/client.ts +170 -0
  81. package/src/targets/csharp/httpclient/fixtures/application-form-encoded.cs +18 -0
  82. package/src/targets/csharp/httpclient/fixtures/application-json.cs +20 -0
  83. package/src/targets/csharp/httpclient/fixtures/cookies.cs +21 -0
  84. package/src/targets/csharp/httpclient/fixtures/custom-method.cs +13 -0
  85. package/src/targets/csharp/httpclient/fixtures/full.cs +26 -0
  86. package/src/targets/csharp/httpclient/fixtures/headers.cs +19 -0
  87. package/src/targets/csharp/httpclient/fixtures/http-insecure.cs +13 -0
  88. package/src/targets/csharp/httpclient/fixtures/jsonObj-multiline.cs +20 -0
  89. package/src/targets/csharp/httpclient/fixtures/jsonObj-null-value.cs +20 -0
  90. package/src/targets/csharp/httpclient/fixtures/multipart-data.cs +38 -0
  91. package/src/targets/csharp/httpclient/fixtures/multipart-file.cs +28 -0
  92. package/src/targets/csharp/httpclient/fixtures/multipart-form-data-no-params.cs +13 -0
  93. package/src/targets/csharp/httpclient/fixtures/multipart-form-data.cs +26 -0
  94. package/src/targets/csharp/httpclient/fixtures/nested.cs +13 -0
  95. package/src/targets/csharp/httpclient/fixtures/query-encoded.cs +13 -0
  96. package/src/targets/csharp/httpclient/fixtures/query.cs +13 -0
  97. package/src/targets/csharp/httpclient/fixtures/short.cs +13 -0
  98. package/src/targets/csharp/httpclient/fixtures/text-plain.cs +20 -0
  99. package/src/targets/csharp/restsharp/client.ts +44 -0
  100. package/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs +5 -0
  101. package/src/targets/csharp/restsharp/fixtures/application-json.cs +5 -0
  102. package/src/targets/csharp/restsharp/fixtures/cookies.cs +5 -0
  103. package/src/targets/csharp/restsharp/fixtures/custom-method.cs +1 -0
  104. package/src/targets/csharp/restsharp/fixtures/full.cs +8 -0
  105. package/src/targets/csharp/restsharp/fixtures/headers.cs +6 -0
  106. package/src/targets/csharp/restsharp/fixtures/http-insecure.cs +3 -0
  107. package/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs +5 -0
  108. package/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs +5 -0
  109. package/src/targets/csharp/restsharp/fixtures/multipart-data.cs +5 -0
  110. package/src/targets/csharp/restsharp/fixtures/multipart-file.cs +5 -0
  111. package/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs +4 -0
  112. package/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs +5 -0
  113. package/src/targets/csharp/restsharp/fixtures/nested.cs +3 -0
  114. package/src/targets/csharp/restsharp/fixtures/query-encoded.cs +3 -0
  115. package/src/targets/csharp/restsharp/fixtures/query.cs +3 -0
  116. package/src/targets/csharp/restsharp/fixtures/short.cs +3 -0
  117. package/src/targets/csharp/restsharp/fixtures/text-plain.cs +5 -0
  118. package/src/targets/csharp/target.ts +17 -0
  119. package/src/targets/go/native/client.test.ts +42 -0
  120. package/src/targets/go/native/client.ts +143 -0
  121. package/src/targets/go/native/fixtures/application-form-encoded.go +28 -0
  122. package/src/targets/go/native/fixtures/application-json.go +28 -0
  123. package/src/targets/go/native/fixtures/boilerplate-option.go +17 -0
  124. package/src/targets/go/native/fixtures/check-errors-option.go +39 -0
  125. package/src/targets/go/native/fixtures/cookies.go +25 -0
  126. package/src/targets/go/native/fixtures/custom-method.go +23 -0
  127. package/src/targets/go/native/fixtures/full.go +30 -0
  128. package/src/targets/go/native/fixtures/headers.go +27 -0
  129. package/src/targets/go/native/fixtures/http-insecure.go +23 -0
  130. package/src/targets/go/native/fixtures/jsonObj-multiline.go +28 -0
  131. package/src/targets/go/native/fixtures/jsonObj-null-value.go +28 -0
  132. package/src/targets/go/native/fixtures/multipart-data.go +28 -0
  133. package/src/targets/go/native/fixtures/multipart-file.go +28 -0
  134. package/src/targets/go/native/fixtures/multipart-form-data-no-params.go +25 -0
  135. package/src/targets/go/native/fixtures/multipart-form-data.go +28 -0
  136. package/src/targets/go/native/fixtures/nested.go +23 -0
  137. package/src/targets/go/native/fixtures/print-body-option.go +25 -0
  138. package/src/targets/go/native/fixtures/query-encoded.go +23 -0
  139. package/src/targets/go/native/fixtures/query.go +23 -0
  140. package/src/targets/go/native/fixtures/short.go +23 -0
  141. package/src/targets/go/native/fixtures/text-plain.go +28 -0
  142. package/src/targets/go/native/fixtures/timeout-option.go +35 -0
  143. package/src/targets/go/target.ts +14 -0
  144. package/src/targets/har-schema.d.ts +4 -0
  145. package/src/targets/http/http1.1/client.ts +89 -0
  146. package/src/targets/http/http1.1/fixtures/application-form-encoded +6 -0
  147. package/src/targets/http/http1.1/fixtures/application-json +6 -0
  148. package/src/targets/http/http1.1/fixtures/cookies +4 -0
  149. package/src/targets/http/http1.1/fixtures/custom-method +3 -0
  150. package/src/targets/http/http1.1/fixtures/full +8 -0
  151. package/src/targets/http/http1.1/fixtures/headers +6 -0
  152. package/src/targets/http/http1.1/fixtures/http-insecure +3 -0
  153. package/src/targets/http/http1.1/fixtures/jsonObj-multiline +8 -0
  154. package/src/targets/http/http1.1/fixtures/jsonObj-null-value +6 -0
  155. package/src/targets/http/http1.1/fixtures/multipart-data +15 -0
  156. package/src/targets/http/http1.1/fixtures/multipart-file +11 -0
  157. package/src/targets/http/http1.1/fixtures/multipart-form-data +10 -0
  158. package/src/targets/http/http1.1/fixtures/multipart-form-data-no-params +4 -0
  159. package/src/targets/http/http1.1/fixtures/nested +3 -0
  160. package/src/targets/http/http1.1/fixtures/query +3 -0
  161. package/src/targets/http/http1.1/fixtures/query-encoded +3 -0
  162. package/src/targets/http/http1.1/fixtures/short +3 -0
  163. package/src/targets/http/http1.1/fixtures/text-plain +6 -0
  164. package/src/targets/http/target.ts +14 -0
  165. package/src/targets/java/asynchttp/client.ts +50 -0
  166. package/src/targets/java/asynchttp/fixtures/application-form-encoded.java +10 -0
  167. package/src/targets/java/asynchttp/fixtures/application-json.java +10 -0
  168. package/src/targets/java/asynchttp/fixtures/cookies.java +9 -0
  169. package/src/targets/java/asynchttp/fixtures/custom-method.java +8 -0
  170. package/src/targets/java/asynchttp/fixtures/full.java +12 -0
  171. package/src/targets/java/asynchttp/fixtures/headers.java +11 -0
  172. package/src/targets/java/asynchttp/fixtures/http-insecure.java +8 -0
  173. package/src/targets/java/asynchttp/fixtures/jsonObj-multiline.java +10 -0
  174. package/src/targets/java/asynchttp/fixtures/jsonObj-null-value.java +10 -0
  175. package/src/targets/java/asynchttp/fixtures/multipart-data.java +10 -0
  176. package/src/targets/java/asynchttp/fixtures/multipart-file.java +10 -0
  177. package/src/targets/java/asynchttp/fixtures/multipart-form-data-no-params.java +9 -0
  178. package/src/targets/java/asynchttp/fixtures/multipart-form-data.java +10 -0
  179. package/src/targets/java/asynchttp/fixtures/nested.java +8 -0
  180. package/src/targets/java/asynchttp/fixtures/query-encoded.java +8 -0
  181. package/src/targets/java/asynchttp/fixtures/query.java +8 -0
  182. package/src/targets/java/asynchttp/fixtures/short.java +8 -0
  183. package/src/targets/java/asynchttp/fixtures/text-plain.java +10 -0
  184. package/src/targets/java/nethttp/client.ts +58 -0
  185. package/src/targets/java/nethttp/fixtures/application-form-encoded.java +7 -0
  186. package/src/targets/java/nethttp/fixtures/application-json.java +7 -0
  187. package/src/targets/java/nethttp/fixtures/cookies.java +7 -0
  188. package/src/targets/java/nethttp/fixtures/custom-method.java +6 -0
  189. package/src/targets/java/nethttp/fixtures/full.java +9 -0
  190. package/src/targets/java/nethttp/fixtures/headers.java +9 -0
  191. package/src/targets/java/nethttp/fixtures/http-insecure.java +6 -0
  192. package/src/targets/java/nethttp/fixtures/jsonObj-multiline.java +7 -0
  193. package/src/targets/java/nethttp/fixtures/jsonObj-null-value.java +7 -0
  194. package/src/targets/java/nethttp/fixtures/multipart-data.java +7 -0
  195. package/src/targets/java/nethttp/fixtures/multipart-file.java +7 -0
  196. package/src/targets/java/nethttp/fixtures/multipart-form-data-no-params.java +7 -0
  197. package/src/targets/java/nethttp/fixtures/multipart-form-data.java +7 -0
  198. package/src/targets/java/nethttp/fixtures/nested.java +6 -0
  199. package/src/targets/java/nethttp/fixtures/query-encoded.java +6 -0
  200. package/src/targets/java/nethttp/fixtures/query.java +6 -0
  201. package/src/targets/java/nethttp/fixtures/short.java +6 -0
  202. package/src/targets/java/nethttp/fixtures/text-plain.java +7 -0
  203. package/src/targets/java/okhttp/client.ts +72 -0
  204. package/src/targets/java/okhttp/fixtures/application-form-encoded.java +11 -0
  205. package/src/targets/java/okhttp/fixtures/application-json.java +11 -0
  206. package/src/targets/java/okhttp/fixtures/cookies.java +9 -0
  207. package/src/targets/java/okhttp/fixtures/custom-method.java +8 -0
  208. package/src/targets/java/okhttp/fixtures/full.java +13 -0
  209. package/src/targets/java/okhttp/fixtures/headers.java +11 -0
  210. package/src/targets/java/okhttp/fixtures/http-insecure.java +8 -0
  211. package/src/targets/java/okhttp/fixtures/jsonObj-multiline.java +11 -0
  212. package/src/targets/java/okhttp/fixtures/jsonObj-null-value.java +11 -0
  213. package/src/targets/java/okhttp/fixtures/multipart-data.java +11 -0
  214. package/src/targets/java/okhttp/fixtures/multipart-file.java +11 -0
  215. package/src/targets/java/okhttp/fixtures/multipart-form-data-no-params.java +9 -0
  216. package/src/targets/java/okhttp/fixtures/multipart-form-data.java +11 -0
  217. package/src/targets/java/okhttp/fixtures/nested.java +8 -0
  218. package/src/targets/java/okhttp/fixtures/query-encoded.java +8 -0
  219. package/src/targets/java/okhttp/fixtures/query.java +8 -0
  220. package/src/targets/java/okhttp/fixtures/short.java +8 -0
  221. package/src/targets/java/okhttp/fixtures/text-plain.java +11 -0
  222. package/src/targets/java/target.ts +21 -0
  223. package/src/targets/java/unirest/client.ts +50 -0
  224. package/src/targets/java/unirest/fixtures/application-form-encoded.java +4 -0
  225. package/src/targets/java/unirest/fixtures/application-json.java +4 -0
  226. package/src/targets/java/unirest/fixtures/cookies.java +3 -0
  227. package/src/targets/java/unirest/fixtures/custom-method.java +2 -0
  228. package/src/targets/java/unirest/fixtures/full.java +6 -0
  229. package/src/targets/java/unirest/fixtures/headers.java +5 -0
  230. package/src/targets/java/unirest/fixtures/http-insecure.java +2 -0
  231. package/src/targets/java/unirest/fixtures/jsonObj-multiline.java +4 -0
  232. package/src/targets/java/unirest/fixtures/jsonObj-null-value.java +4 -0
  233. package/src/targets/java/unirest/fixtures/multipart-data.java +4 -0
  234. package/src/targets/java/unirest/fixtures/multipart-file.java +4 -0
  235. package/src/targets/java/unirest/fixtures/multipart-form-data-no-params.java +3 -0
  236. package/src/targets/java/unirest/fixtures/multipart-form-data.java +4 -0
  237. package/src/targets/java/unirest/fixtures/nested.java +2 -0
  238. package/src/targets/java/unirest/fixtures/query-encoded.java +2 -0
  239. package/src/targets/java/unirest/fixtures/query.java +2 -0
  240. package/src/targets/java/unirest/fixtures/short.java +2 -0
  241. package/src/targets/java/unirest/fixtures/text-plain.java +4 -0
  242. package/src/targets/javascript/axios/client.ts +109 -0
  243. package/src/targets/javascript/axios/fixtures/application-form-encoded.js +21 -0
  244. package/src/targets/javascript/axios/fixtures/application-json.js +24 -0
  245. package/src/targets/javascript/axios/fixtures/cookies.js +16 -0
  246. package/src/targets/javascript/axios/fixtures/custom-method.js +12 -0
  247. package/src/targets/javascript/axios/fixtures/full.js +25 -0
  248. package/src/targets/javascript/axios/fixtures/headers.js +16 -0
  249. package/src/targets/javascript/axios/fixtures/http-insecure.js +12 -0
  250. package/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +17 -0
  251. package/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +17 -0
  252. package/src/targets/javascript/axios/fixtures/multipart-data.js +21 -0
  253. package/src/targets/javascript/axios/fixtures/multipart-file.js +20 -0
  254. package/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +16 -0
  255. package/src/targets/javascript/axios/fixtures/multipart-form-data.js +20 -0
  256. package/src/targets/javascript/axios/fixtures/nested.js +16 -0
  257. package/src/targets/javascript/axios/fixtures/query-encoded.js +19 -0
  258. package/src/targets/javascript/axios/fixtures/query.js +16 -0
  259. package/src/targets/javascript/axios/fixtures/short.js +12 -0
  260. package/src/targets/javascript/axios/fixtures/text-plain.js +17 -0
  261. package/src/targets/javascript/fetch/client.ts +129 -0
  262. package/src/targets/javascript/fetch/fixtures/application-form-encoded.js +10 -0
  263. package/src/targets/javascript/fetch/fixtures/application-json.js +17 -0
  264. package/src/targets/javascript/fetch/fixtures/cookies.js +6 -0
  265. package/src/targets/javascript/fetch/fixtures/custom-method.js +6 -0
  266. package/src/targets/javascript/fetch/fixtures/full.js +14 -0
  267. package/src/targets/javascript/fetch/fixtures/headers.js +9 -0
  268. package/src/targets/javascript/fetch/fixtures/http-insecure.js +6 -0
  269. package/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +10 -0
  270. package/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +10 -0
  271. package/src/targets/javascript/fetch/fixtures/multipart-data.js +12 -0
  272. package/src/targets/javascript/fetch/fixtures/multipart-file.js +11 -0
  273. package/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +6 -0
  274. package/src/targets/javascript/fetch/fixtures/multipart-form-data.js +11 -0
  275. package/src/targets/javascript/fetch/fixtures/nested.js +6 -0
  276. package/src/targets/javascript/fetch/fixtures/query-encoded.js +6 -0
  277. package/src/targets/javascript/fetch/fixtures/query.js +6 -0
  278. package/src/targets/javascript/fetch/fixtures/short.js +6 -0
  279. package/src/targets/javascript/fetch/fixtures/text-plain.js +6 -0
  280. package/src/targets/javascript/jquery/client.ts +95 -0
  281. package/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
  282. package/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
  283. package/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
  284. package/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
  285. package/src/targets/javascript/jquery/fixtures/full.js +18 -0
  286. package/src/targets/javascript/jquery/fixtures/headers.js +15 -0
  287. package/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
  288. package/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
  289. package/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
  290. package/src/targets/javascript/jquery/fixtures/multipart-data.js +19 -0
  291. package/src/targets/javascript/jquery/fixtures/multipart-file.js +18 -0
  292. package/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
  293. package/src/targets/javascript/jquery/fixtures/multipart-form-data.js +18 -0
  294. package/src/targets/javascript/jquery/fixtures/nested.js +11 -0
  295. package/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
  296. package/src/targets/javascript/jquery/fixtures/query.js +11 -0
  297. package/src/targets/javascript/jquery/fixtures/short.js +11 -0
  298. package/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
  299. package/src/targets/javascript/target.ts +21 -0
  300. package/src/targets/javascript/xhr/client.test.ts +18 -0
  301. package/src/targets/javascript/xhr/client.ts +100 -0
  302. package/src/targets/javascript/xhr/fixtures/application-form-encoded.js +15 -0
  303. package/src/targets/javascript/xhr/fixtures/application-json.js +34 -0
  304. package/src/targets/javascript/xhr/fixtures/cookies.js +15 -0
  305. package/src/targets/javascript/xhr/fixtures/cors.js +13 -0
  306. package/src/targets/javascript/xhr/fixtures/custom-method.js +14 -0
  307. package/src/targets/javascript/xhr/fixtures/full.js +17 -0
  308. package/src/targets/javascript/xhr/fixtures/headers.js +17 -0
  309. package/src/targets/javascript/xhr/fixtures/http-insecure.js +14 -0
  310. package/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +17 -0
  311. package/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +17 -0
  312. package/src/targets/javascript/xhr/fixtures/multipart-data.js +16 -0
  313. package/src/targets/javascript/xhr/fixtures/multipart-file.js +15 -0
  314. package/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +13 -0
  315. package/src/targets/javascript/xhr/fixtures/multipart-form-data.js +15 -0
  316. package/src/targets/javascript/xhr/fixtures/nested.js +14 -0
  317. package/src/targets/javascript/xhr/fixtures/query-encoded.js +14 -0
  318. package/src/targets/javascript/xhr/fixtures/query.js +14 -0
  319. package/src/targets/javascript/xhr/fixtures/short.js +14 -0
  320. package/src/targets/javascript/xhr/fixtures/text-plain.js +15 -0
  321. package/src/targets/kotlin/okhttp/client.ts +73 -0
  322. package/src/targets/kotlin/okhttp/fixtures/application-form-encoded.kt +11 -0
  323. package/src/targets/kotlin/okhttp/fixtures/application-json.kt +11 -0
  324. package/src/targets/kotlin/okhttp/fixtures/cookies.kt +9 -0
  325. package/src/targets/kotlin/okhttp/fixtures/custom-method.kt +8 -0
  326. package/src/targets/kotlin/okhttp/fixtures/full.kt +13 -0
  327. package/src/targets/kotlin/okhttp/fixtures/headers.kt +11 -0
  328. package/src/targets/kotlin/okhttp/fixtures/http-insecure.kt +8 -0
  329. package/src/targets/kotlin/okhttp/fixtures/jsonObj-multiline.kt +11 -0
  330. package/src/targets/kotlin/okhttp/fixtures/jsonObj-null-value.kt +11 -0
  331. package/src/targets/kotlin/okhttp/fixtures/multipart-data.kt +11 -0
  332. package/src/targets/kotlin/okhttp/fixtures/multipart-file.kt +11 -0
  333. package/src/targets/kotlin/okhttp/fixtures/multipart-form-data-no-params.kt +9 -0
  334. package/src/targets/kotlin/okhttp/fixtures/multipart-form-data.kt +11 -0
  335. package/src/targets/kotlin/okhttp/fixtures/nested.kt +8 -0
  336. package/src/targets/kotlin/okhttp/fixtures/query-encoded.kt +8 -0
  337. package/src/targets/kotlin/okhttp/fixtures/query.kt +8 -0
  338. package/src/targets/kotlin/okhttp/fixtures/short.kt +8 -0
  339. package/src/targets/kotlin/okhttp/fixtures/text-plain.kt +11 -0
  340. package/src/targets/kotlin/target.ts +14 -0
  341. package/src/targets/node/axios/client.ts +89 -0
  342. package/src/targets/node/axios/fixtures/application-form-encoded.js +22 -0
  343. package/src/targets/node/axios/fixtures/application-json.js +24 -0
  344. package/src/targets/node/axios/fixtures/cookies.js +16 -0
  345. package/src/targets/node/axios/fixtures/custom-method.js +12 -0
  346. package/src/targets/node/axios/fixtures/full.js +25 -0
  347. package/src/targets/node/axios/fixtures/headers.js +16 -0
  348. package/src/targets/node/axios/fixtures/http-insecure.js +12 -0
  349. package/src/targets/node/axios/fixtures/jsonObj-multiline.js +17 -0
  350. package/src/targets/node/axios/fixtures/jsonObj-null-value.js +17 -0
  351. package/src/targets/node/axios/fixtures/multipart-data.js +17 -0
  352. package/src/targets/node/axios/fixtures/multipart-file.js +17 -0
  353. package/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +16 -0
  354. package/src/targets/node/axios/fixtures/multipart-form-data.js +17 -0
  355. package/src/targets/node/axios/fixtures/nested.js +15 -0
  356. package/src/targets/node/axios/fixtures/query-encoded.js +15 -0
  357. package/src/targets/node/axios/fixtures/query.js +15 -0
  358. package/src/targets/node/axios/fixtures/short.js +12 -0
  359. package/src/targets/node/axios/fixtures/text-plain.js +17 -0
  360. package/src/targets/node/fetch/client.ts +153 -0
  361. package/src/targets/node/fetch/fixtures/application-form-encoded.js +18 -0
  362. package/src/targets/node/fetch/fixtures/application-json.js +20 -0
  363. package/src/targets/node/fetch/fixtures/cookies.js +9 -0
  364. package/src/targets/node/fetch/fixtures/custom-method.js +9 -0
  365. package/src/targets/node/fetch/fixtures/full.js +21 -0
  366. package/src/targets/node/fetch/fixtures/headers.js +12 -0
  367. package/src/targets/node/fetch/fixtures/http-insecure.js +9 -0
  368. package/src/targets/node/fetch/fixtures/jsonObj-multiline.js +13 -0
  369. package/src/targets/node/fetch/fixtures/jsonObj-null-value.js +13 -0
  370. package/src/targets/node/fetch/fixtures/multipart-data.js +17 -0
  371. package/src/targets/node/fetch/fixtures/multipart-file.js +16 -0
  372. package/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +9 -0
  373. package/src/targets/node/fetch/fixtures/multipart-form-data.js +15 -0
  374. package/src/targets/node/fetch/fixtures/nested.js +9 -0
  375. package/src/targets/node/fetch/fixtures/query-encoded.js +9 -0
  376. package/src/targets/node/fetch/fixtures/query.js +9 -0
  377. package/src/targets/node/fetch/fixtures/short.js +9 -0
  378. package/src/targets/node/fetch/fixtures/text-plain.js +9 -0
  379. package/src/targets/node/native/client.ts +91 -0
  380. package/src/targets/node/native/fixtures/application-form-encoded.js +28 -0
  381. package/src/targets/node/native/fixtures/application-json.js +34 -0
  382. package/src/targets/node/native/fixtures/cookies.js +26 -0
  383. package/src/targets/node/native/fixtures/custom-method.js +24 -0
  384. package/src/targets/node/native/fixtures/full.js +30 -0
  385. package/src/targets/node/native/fixtures/headers.js +28 -0
  386. package/src/targets/node/native/fixtures/http-insecure.js +24 -0
  387. package/src/targets/node/native/fixtures/jsonObj-multiline.js +27 -0
  388. package/src/targets/node/native/fixtures/jsonObj-null-value.js +27 -0
  389. package/src/targets/node/native/fixtures/multipart-data.js +27 -0
  390. package/src/targets/node/native/fixtures/multipart-file.js +27 -0
  391. package/src/targets/node/native/fixtures/multipart-form-data-no-params.js +26 -0
  392. package/src/targets/node/native/fixtures/multipart-form-data.js +27 -0
  393. package/src/targets/node/native/fixtures/nested.js +24 -0
  394. package/src/targets/node/native/fixtures/query-encoded.js +24 -0
  395. package/src/targets/node/native/fixtures/query.js +24 -0
  396. package/src/targets/node/native/fixtures/short.js +24 -0
  397. package/src/targets/node/native/fixtures/text-plain.js +27 -0
  398. package/src/targets/node/request/client.ts +130 -0
  399. package/src/targets/node/request/fixtures/application-form-encoded.js +14 -0
  400. package/src/targets/node/request/fixtures/application-json.js +22 -0
  401. package/src/targets/node/request/fixtures/cookies.js +13 -0
  402. package/src/targets/node/request/fixtures/custom-method.js +9 -0
  403. package/src/targets/node/request/fixtures/full.js +22 -0
  404. package/src/targets/node/request/fixtures/headers.js +13 -0
  405. package/src/targets/node/request/fixtures/http-insecure.js +9 -0
  406. package/src/targets/node/request/fixtures/jsonObj-multiline.js +15 -0
  407. package/src/targets/node/request/fixtures/jsonObj-null-value.js +15 -0
  408. package/src/targets/node/request/fixtures/multipart-data.js +21 -0
  409. package/src/targets/node/request/fixtures/multipart-file.js +20 -0
  410. package/src/targets/node/request/fixtures/multipart-form-data-no-params.js +13 -0
  411. package/src/targets/node/request/fixtures/multipart-form-data.js +14 -0
  412. package/src/targets/node/request/fixtures/nested.js +12 -0
  413. package/src/targets/node/request/fixtures/query-encoded.js +12 -0
  414. package/src/targets/node/request/fixtures/query.js +12 -0
  415. package/src/targets/node/request/fixtures/short.js +9 -0
  416. package/src/targets/node/request/fixtures/text-plain.js +14 -0
  417. package/src/targets/node/target.ts +23 -0
  418. package/src/targets/node/unirest/client.ts +129 -0
  419. package/src/targets/node/unirest/fixtures/application-form-encoded.js +18 -0
  420. package/src/targets/node/unirest/fixtures/application-json.js +35 -0
  421. package/src/targets/node/unirest/fixtures/cookies.js +14 -0
  422. package/src/targets/node/unirest/fixtures/custom-method.js +9 -0
  423. package/src/targets/node/unirest/fixtures/full.js +32 -0
  424. package/src/targets/node/unirest/fixtures/headers.js +15 -0
  425. package/src/targets/node/unirest/fixtures/http-insecure.js +9 -0
  426. package/src/targets/node/unirest/fixtures/jsonObj-multiline.js +18 -0
  427. package/src/targets/node/unirest/fixtures/jsonObj-null-value.js +18 -0
  428. package/src/targets/node/unirest/fixtures/multipart-data.js +23 -0
  429. package/src/targets/node/unirest/fixtures/multipart-file.js +21 -0
  430. package/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +13 -0
  431. package/src/targets/node/unirest/fixtures/multipart-form-data.js +19 -0
  432. package/src/targets/node/unirest/fixtures/nested.js +15 -0
  433. package/src/targets/node/unirest/fixtures/query-encoded.js +14 -0
  434. package/src/targets/node/unirest/fixtures/query.js +18 -0
  435. package/src/targets/node/unirest/fixtures/short.js +9 -0
  436. package/src/targets/node/unirest/fixtures/text-plain.js +15 -0
  437. package/src/targets/objc/helpers.ts +60 -0
  438. package/src/targets/objc/nsurlsession/client.test.ts +36 -0
  439. package/src/targets/objc/nsurlsession/client.ts +164 -0
  440. package/src/targets/objc/nsurlsession/fixtures/application-form-encoded.m +25 -0
  441. package/src/targets/objc/nsurlsession/fixtures/application-json.m +30 -0
  442. package/src/targets/objc/nsurlsession/fixtures/cookies.m +21 -0
  443. package/src/targets/objc/nsurlsession/fixtures/custom-method.m +18 -0
  444. package/src/targets/objc/nsurlsession/fixtures/full.m +26 -0
  445. package/src/targets/objc/nsurlsession/fixtures/headers.m +23 -0
  446. package/src/targets/objc/nsurlsession/fixtures/http-insecure.m +18 -0
  447. package/src/targets/objc/nsurlsession/fixtures/indent-option.m +18 -0
  448. package/src/targets/objc/nsurlsession/fixtures/json-with-null-value.m +25 -0
  449. package/src/targets/objc/nsurlsession/fixtures/jsonObj-multiline.m +25 -0
  450. package/src/targets/objc/nsurlsession/fixtures/jsonObj-null-value.m +25 -0
  451. package/src/targets/objc/nsurlsession/fixtures/multipart-data.m +44 -0
  452. package/src/targets/objc/nsurlsession/fixtures/multipart-file.m +43 -0
  453. package/src/targets/objc/nsurlsession/fixtures/multipart-form-data-no-params.m +21 -0
  454. package/src/targets/objc/nsurlsession/fixtures/multipart-form-data.m +43 -0
  455. package/src/targets/objc/nsurlsession/fixtures/nested.m +18 -0
  456. package/src/targets/objc/nsurlsession/fixtures/pretty-option.m +24 -0
  457. package/src/targets/objc/nsurlsession/fixtures/query-encoded.m +18 -0
  458. package/src/targets/objc/nsurlsession/fixtures/query.m +18 -0
  459. package/src/targets/objc/nsurlsession/fixtures/short.m +18 -0
  460. package/src/targets/objc/nsurlsession/fixtures/text-plain.m +24 -0
  461. package/src/targets/objc/nsurlsession/fixtures/timeout-option.m +18 -0
  462. package/src/targets/objc/target.ts +14 -0
  463. package/src/targets/ocaml/cohttp/client.ts +72 -0
  464. package/src/targets/ocaml/cohttp/fixtures/application-form-encoded.ml +11 -0
  465. package/src/targets/ocaml/cohttp/fixtures/application-json.ml +11 -0
  466. package/src/targets/ocaml/cohttp/fixtures/cookies.ml +10 -0
  467. package/src/targets/ocaml/cohttp/fixtures/custom-method.ml +9 -0
  468. package/src/targets/ocaml/cohttp/fixtures/full.ml +15 -0
  469. package/src/targets/ocaml/cohttp/fixtures/headers.ml +14 -0
  470. package/src/targets/ocaml/cohttp/fixtures/http-insecure.ml +9 -0
  471. package/src/targets/ocaml/cohttp/fixtures/jsonObj-multiline.ml +11 -0
  472. package/src/targets/ocaml/cohttp/fixtures/jsonObj-null-value.ml +11 -0
  473. package/src/targets/ocaml/cohttp/fixtures/multipart-data.ml +11 -0
  474. package/src/targets/ocaml/cohttp/fixtures/multipart-file.ml +11 -0
  475. package/src/targets/ocaml/cohttp/fixtures/multipart-form-data-no-params.ml +10 -0
  476. package/src/targets/ocaml/cohttp/fixtures/multipart-form-data.ml +11 -0
  477. package/src/targets/ocaml/cohttp/fixtures/nested.ml +9 -0
  478. package/src/targets/ocaml/cohttp/fixtures/query-encoded.ml +9 -0
  479. package/src/targets/ocaml/cohttp/fixtures/query.ml +9 -0
  480. package/src/targets/ocaml/cohttp/fixtures/short.ml +9 -0
  481. package/src/targets/ocaml/cohttp/fixtures/text-plain.ml +11 -0
  482. package/src/targets/ocaml/target.ts +14 -0
  483. package/src/targets/php/curl/client.ts +154 -0
  484. package/src/targets/php/curl/fixtures/application-form-encoded.php +28 -0
  485. package/src/targets/php/curl/fixtures/application-json.php +28 -0
  486. package/src/targets/php/curl/fixtures/cookies.php +25 -0
  487. package/src/targets/php/curl/fixtures/custom-method.php +24 -0
  488. package/src/targets/php/curl/fixtures/full.php +30 -0
  489. package/src/targets/php/curl/fixtures/headers.php +29 -0
  490. package/src/targets/php/curl/fixtures/http-insecure.php +24 -0
  491. package/src/targets/php/curl/fixtures/jsonObj-multiline.php +28 -0
  492. package/src/targets/php/curl/fixtures/jsonObj-null-value.php +28 -0
  493. package/src/targets/php/curl/fixtures/multipart-data.php +28 -0
  494. package/src/targets/php/curl/fixtures/multipart-file.php +28 -0
  495. package/src/targets/php/curl/fixtures/multipart-form-data-no-params.php +28 -0
  496. package/src/targets/php/curl/fixtures/multipart-form-data.php +28 -0
  497. package/src/targets/php/curl/fixtures/nested.php +24 -0
  498. package/src/targets/php/curl/fixtures/query-encoded.php +24 -0
  499. package/src/targets/php/curl/fixtures/query.php +24 -0
  500. package/src/targets/php/curl/fixtures/short.php +24 -0
  501. package/src/targets/php/curl/fixtures/text-plain.php +28 -0
  502. package/src/targets/php/guzzle/client.ts +151 -0
  503. package/src/targets/php/guzzle/fixtures/application-form-encoded.php +16 -0
  504. package/src/targets/php/guzzle/fixtures/application-json.php +13 -0
  505. package/src/targets/php/guzzle/fixtures/cookies.php +12 -0
  506. package/src/targets/php/guzzle/fixtures/custom-method.php +8 -0
  507. package/src/targets/php/guzzle/fixtures/full.php +17 -0
  508. package/src/targets/php/guzzle/fixtures/headers.php +14 -0
  509. package/src/targets/php/guzzle/fixtures/http-insecure.php +8 -0
  510. package/src/targets/php/guzzle/fixtures/jsonObj-multiline.php +15 -0
  511. package/src/targets/php/guzzle/fixtures/jsonObj-null-value.php +13 -0
  512. package/src/targets/php/guzzle/fixtures/multipart-data.php +23 -0
  513. package/src/targets/php/guzzle/fixtures/multipart-file.php +19 -0
  514. package/src/targets/php/guzzle/fixtures/multipart-form-data-no-params.php +12 -0
  515. package/src/targets/php/guzzle/fixtures/multipart-form-data.php +15 -0
  516. package/src/targets/php/guzzle/fixtures/nested.php +8 -0
  517. package/src/targets/php/guzzle/fixtures/query-encoded.php +8 -0
  518. package/src/targets/php/guzzle/fixtures/query.php +8 -0
  519. package/src/targets/php/guzzle/fixtures/short.php +8 -0
  520. package/src/targets/php/guzzle/fixtures/text-plain.php +13 -0
  521. package/src/targets/php/helpers.ts +67 -0
  522. package/src/targets/php/http1/client.ts +103 -0
  523. package/src/targets/php/http1/fixtures/application-form-encoded.php +23 -0
  524. package/src/targets/php/http1/fixtures/application-json.php +19 -0
  525. package/src/targets/php/http1/fixtures/cookies.php +18 -0
  526. package/src/targets/php/http1/fixtures/custom-method.php +13 -0
  527. package/src/targets/php/http1/fixtures/full.php +37 -0
  528. package/src/targets/php/http1/fixtures/headers.php +19 -0
  529. package/src/targets/php/http1/fixtures/http-insecure.php +13 -0
  530. package/src/targets/php/http1/fixtures/jsonObj-multiline.php +21 -0
  531. package/src/targets/php/http1/fixtures/jsonObj-null-value.php +19 -0
  532. package/src/targets/php/http1/fixtures/multipart-data.php +29 -0
  533. package/src/targets/php/http1/fixtures/multipart-file.php +25 -0
  534. package/src/targets/php/http1/fixtures/multipart-form-data-no-params.php +17 -0
  535. package/src/targets/php/http1/fixtures/multipart-form-data.php +24 -0
  536. package/src/targets/php/http1/fixtures/nested.php +19 -0
  537. package/src/targets/php/http1/fixtures/query-encoded.php +18 -0
  538. package/src/targets/php/http1/fixtures/query.php +22 -0
  539. package/src/targets/php/http1/fixtures/short.php +13 -0
  540. package/src/targets/php/http1/fixtures/text-plain.php +19 -0
  541. package/src/targets/php/http2/client.ts +153 -0
  542. package/src/targets/php/http2/fixtures/application-form-encoded.php +23 -0
  543. package/src/targets/php/http2/fixtures/application-json.php +20 -0
  544. package/src/targets/php/http2/fixtures/cookies.php +17 -0
  545. package/src/targets/php/http2/fixtures/custom-method.php +11 -0
  546. package/src/targets/php/http2/fixtures/full.php +38 -0
  547. package/src/targets/php/http2/fixtures/headers.php +17 -0
  548. package/src/targets/php/http2/fixtures/http-insecure.php +11 -0
  549. package/src/targets/php/http2/fixtures/jsonObj-multiline.php +22 -0
  550. package/src/targets/php/http2/fixtures/jsonObj-null-value.php +20 -0
  551. package/src/targets/php/http2/fixtures/multipart-data.php +25 -0
  552. package/src/targets/php/http2/fixtures/multipart-file.php +23 -0
  553. package/src/targets/php/http2/fixtures/multipart-form-data-no-params.php +15 -0
  554. package/src/targets/php/http2/fixtures/multipart-form-data.php +18 -0
  555. package/src/targets/php/http2/fixtures/nested.php +17 -0
  556. package/src/targets/php/http2/fixtures/query-encoded.php +16 -0
  557. package/src/targets/php/http2/fixtures/query.php +20 -0
  558. package/src/targets/php/http2/fixtures/short.php +11 -0
  559. package/src/targets/php/http2/fixtures/text-plain.php +20 -0
  560. package/src/targets/php/target.ts +21 -0
  561. package/src/targets/powershell/common.ts +58 -0
  562. package/src/targets/powershell/restmethod/client.ts +12 -0
  563. package/src/targets/powershell/restmethod/fixtures/application-form-encoded.ps1 +3 -0
  564. package/src/targets/powershell/restmethod/fixtures/application-json.ps1 +3 -0
  565. package/src/targets/powershell/restmethod/fixtures/cookies.ps1 +12 -0
  566. package/src/targets/powershell/restmethod/fixtures/custom-method.ps1 +1 -0
  567. package/src/targets/powershell/restmethod/fixtures/full.ps1 +15 -0
  568. package/src/targets/powershell/restmethod/fixtures/headers.ps1 +5 -0
  569. package/src/targets/powershell/restmethod/fixtures/http-insecure.ps1 +1 -0
  570. package/src/targets/powershell/restmethod/fixtures/jsonObj-multiline.ps1 +5 -0
  571. package/src/targets/powershell/restmethod/fixtures/jsonObj-null-value.ps1 +3 -0
  572. package/src/targets/powershell/restmethod/fixtures/multipart-data.ps1 +13 -0
  573. package/src/targets/powershell/restmethod/fixtures/multipart-file.ps1 +9 -0
  574. package/src/targets/powershell/restmethod/fixtures/multipart-form-data-no-params.ps1 +3 -0
  575. package/src/targets/powershell/restmethod/fixtures/multipart-form-data.ps1 +8 -0
  576. package/src/targets/powershell/restmethod/fixtures/nested.ps1 +1 -0
  577. package/src/targets/powershell/restmethod/fixtures/query-encoded.ps1 +1 -0
  578. package/src/targets/powershell/restmethod/fixtures/query.ps1 +1 -0
  579. package/src/targets/powershell/restmethod/fixtures/short.ps1 +1 -0
  580. package/src/targets/powershell/restmethod/fixtures/text-plain.ps1 +3 -0
  581. package/src/targets/powershell/target.ts +16 -0
  582. package/src/targets/powershell/webrequest/client.ts +12 -0
  583. package/src/targets/powershell/webrequest/fixtures/application-form-encoded.ps1 +3 -0
  584. package/src/targets/powershell/webrequest/fixtures/application-json.ps1 +3 -0
  585. package/src/targets/powershell/webrequest/fixtures/cookies.ps1 +12 -0
  586. package/src/targets/powershell/webrequest/fixtures/custom-method.ps1 +1 -0
  587. package/src/targets/powershell/webrequest/fixtures/full.ps1 +15 -0
  588. package/src/targets/powershell/webrequest/fixtures/headers.ps1 +5 -0
  589. package/src/targets/powershell/webrequest/fixtures/http-insecure.ps1 +1 -0
  590. package/src/targets/powershell/webrequest/fixtures/jsonObj-multiline.ps1 +5 -0
  591. package/src/targets/powershell/webrequest/fixtures/jsonObj-null-value.ps1 +3 -0
  592. package/src/targets/powershell/webrequest/fixtures/multipart-data.ps1 +13 -0
  593. package/src/targets/powershell/webrequest/fixtures/multipart-file.ps1 +9 -0
  594. package/src/targets/powershell/webrequest/fixtures/multipart-form-data-no-params.ps1 +3 -0
  595. package/src/targets/powershell/webrequest/fixtures/multipart-form-data.ps1 +8 -0
  596. package/src/targets/powershell/webrequest/fixtures/nested.ps1 +1 -0
  597. package/src/targets/powershell/webrequest/fixtures/query-encoded.ps1 +1 -0
  598. package/src/targets/powershell/webrequest/fixtures/query.ps1 +1 -0
  599. package/src/targets/powershell/webrequest/fixtures/short.ps1 +1 -0
  600. package/src/targets/powershell/webrequest/fixtures/text-plain.ps1 +3 -0
  601. package/src/targets/python/helpers.ts +81 -0
  602. package/src/targets/python/requests/client.ts +175 -0
  603. package/src/targets/python/requests/fixtures/application-form-encoded.py +10 -0
  604. package/src/targets/python/requests/fixtures/application-json.py +17 -0
  605. package/src/targets/python/requests/fixtures/cookies.py +9 -0
  606. package/src/targets/python/requests/fixtures/custom-method.py +7 -0
  607. package/src/targets/python/requests/fixtures/full.py +14 -0
  608. package/src/targets/python/requests/fixtures/headers.py +13 -0
  609. package/src/targets/python/requests/fixtures/http-insecure.py +7 -0
  610. package/src/targets/python/requests/fixtures/jsonObj-multiline.py +10 -0
  611. package/src/targets/python/requests/fixtures/jsonObj-null-value.py +10 -0
  612. package/src/targets/python/requests/fixtures/multipart-data.py +10 -0
  613. package/src/targets/python/requests/fixtures/multipart-file.py +9 -0
  614. package/src/targets/python/requests/fixtures/multipart-form-data-no-params.py +9 -0
  615. package/src/targets/python/requests/fixtures/multipart-form-data.py +10 -0
  616. package/src/targets/python/requests/fixtures/nested.py +7 -0
  617. package/src/targets/python/requests/fixtures/query-encoded.py +7 -0
  618. package/src/targets/python/requests/fixtures/query.py +7 -0
  619. package/src/targets/python/requests/fixtures/short.py +7 -0
  620. package/src/targets/python/requests/fixtures/text-plain.py +10 -0
  621. package/src/targets/python/target.ts +15 -0
  622. package/src/targets/r/httr/client.test.ts +29 -0
  623. package/src/targets/r/httr/client.ts +146 -0
  624. package/src/targets/r/httr/fixtures/application-form-encoded.r +11 -0
  625. package/src/targets/r/httr/fixtures/application-json.r +11 -0
  626. package/src/targets/r/httr/fixtures/cookies.r +7 -0
  627. package/src/targets/r/httr/fixtures/custom-method.r +7 -0
  628. package/src/targets/r/httr/fixtures/full.r +16 -0
  629. package/src/targets/r/httr/fixtures/headers.r +7 -0
  630. package/src/targets/r/httr/fixtures/http-insecure.r +7 -0
  631. package/src/targets/r/httr/fixtures/jsonObj-multiline.r +11 -0
  632. package/src/targets/r/httr/fixtures/jsonObj-null-value.r +11 -0
  633. package/src/targets/r/httr/fixtures/multipart-data.r +11 -0
  634. package/src/targets/r/httr/fixtures/multipart-file.r +11 -0
  635. package/src/targets/r/httr/fixtures/multipart-form-data-no-params.r +9 -0
  636. package/src/targets/r/httr/fixtures/multipart-form-data.r +11 -0
  637. package/src/targets/r/httr/fixtures/nested.r +12 -0
  638. package/src/targets/r/httr/fixtures/query-encoded.r +12 -0
  639. package/src/targets/r/httr/fixtures/query-two-params.r +12 -0
  640. package/src/targets/r/httr/fixtures/query.r +12 -0
  641. package/src/targets/r/httr/fixtures/short.r +7 -0
  642. package/src/targets/r/httr/fixtures/text-plain.r +11 -0
  643. package/src/targets/r/target.ts +14 -0
  644. package/src/targets/ruby/native/client.ts +78 -0
  645. package/src/targets/ruby/native/fixtures/application-form-encoded.rb +15 -0
  646. package/src/targets/ruby/native/fixtures/application-json.rb +15 -0
  647. package/src/targets/ruby/native/fixtures/cookies.rb +14 -0
  648. package/src/targets/ruby/native/fixtures/custom-method.rb +19 -0
  649. package/src/targets/ruby/native/fixtures/full.rb +17 -0
  650. package/src/targets/ruby/native/fixtures/headers.rb +16 -0
  651. package/src/targets/ruby/native/fixtures/http-insecure.rb +11 -0
  652. package/src/targets/ruby/native/fixtures/jsonObj-multiline.rb +15 -0
  653. package/src/targets/ruby/native/fixtures/jsonObj-null-value.rb +15 -0
  654. package/src/targets/ruby/native/fixtures/multipart-data.rb +15 -0
  655. package/src/targets/ruby/native/fixtures/multipart-file.rb +15 -0
  656. package/src/targets/ruby/native/fixtures/multipart-form-data-no-params.rb +14 -0
  657. package/src/targets/ruby/native/fixtures/multipart-form-data.rb +15 -0
  658. package/src/targets/ruby/native/fixtures/nested.rb +13 -0
  659. package/src/targets/ruby/native/fixtures/query-encoded.rb +13 -0
  660. package/src/targets/ruby/native/fixtures/query.rb +13 -0
  661. package/src/targets/ruby/native/fixtures/short.rb +13 -0
  662. package/src/targets/ruby/native/fixtures/text-plain.rb +15 -0
  663. package/src/targets/ruby/target.ts +14 -0
  664. package/src/targets/shell/curl/client.test.ts +157 -0
  665. package/src/targets/shell/curl/client.ts +193 -0
  666. package/src/targets/shell/curl/fixtures/application-form-encoded.sh +5 -0
  667. package/src/targets/shell/curl/fixtures/application-json.sh +25 -0
  668. package/src/targets/shell/curl/fixtures/binary-option.sh +1 -0
  669. package/src/targets/shell/curl/fixtures/cookies.sh +3 -0
  670. package/src/targets/shell/curl/fixtures/custom-indentation.sh +6 -0
  671. package/src/targets/shell/curl/fixtures/custom-method.sh +2 -0
  672. package/src/targets/shell/curl/fixtures/dont-deglob.sh +1 -0
  673. package/src/targets/shell/curl/fixtures/full.sh +6 -0
  674. package/src/targets/shell/curl/fixtures/globoff-option.sh +1 -0
  675. package/src/targets/shell/curl/fixtures/harIsAlreadyEncoded-option-already-encoded.sh +3 -0
  676. package/src/targets/shell/curl/fixtures/harIsAlreadyEncoded=option-escape-brackets.sh +2 -0
  677. package/src/targets/shell/curl/fixtures/headers.sh +5 -0
  678. package/src/targets/shell/curl/fixtures/heredoc-json-encoded-data.sh +9 -0
  679. package/src/targets/shell/curl/fixtures/http-insecure.sh +2 -0
  680. package/src/targets/shell/curl/fixtures/http1.sh +3 -0
  681. package/src/targets/shell/curl/fixtures/http10.sh +1 -0
  682. package/src/targets/shell/curl/fixtures/json-payloads-smaller-than-20-characters.sh +4 -0
  683. package/src/targets/shell/curl/fixtures/jsonObj-multiline.sh +6 -0
  684. package/src/targets/shell/curl/fixtures/jsonObj-null-value.sh +4 -0
  685. package/src/targets/shell/curl/fixtures/long-globoff-option.sh +1 -0
  686. package/src/targets/shell/curl/fixtures/multipart-data.sh +5 -0
  687. package/src/targets/shell/curl/fixtures/multipart-file.sh +4 -0
  688. package/src/targets/shell/curl/fixtures/multipart-form-data-no-params.sh +3 -0
  689. package/src/targets/shell/curl/fixtures/multipart-form-data.sh +4 -0
  690. package/src/targets/shell/curl/fixtures/nested.sh +2 -0
  691. package/src/targets/shell/curl/fixtures/query-encoded.sh +2 -0
  692. package/src/targets/shell/curl/fixtures/query.sh +2 -0
  693. package/src/targets/shell/curl/fixtures/short-options.sh +1 -0
  694. package/src/targets/shell/curl/fixtures/short.sh +2 -0
  695. package/src/targets/shell/curl/fixtures/text-plain.sh +4 -0
  696. package/src/targets/shell/curl/fixtures/urlencode.sh +5 -0
  697. package/src/targets/shell/httpie/client.test.ts +72 -0
  698. package/src/targets/shell/httpie/client.ts +144 -0
  699. package/src/targets/shell/httpie/fixtures/application-form-encoded.sh +4 -0
  700. package/src/targets/shell/httpie/fixtures/application-json.sh +3 -0
  701. package/src/targets/shell/httpie/fixtures/build-parameters.sh +1 -0
  702. package/src/targets/shell/httpie/fixtures/cookies.sh +2 -0
  703. package/src/targets/shell/httpie/fixtures/custom-indentation.sh +5 -0
  704. package/src/targets/shell/httpie/fixtures/custom-method.sh +1 -0
  705. package/src/targets/shell/httpie/fixtures/full.sh +5 -0
  706. package/src/targets/shell/httpie/fixtures/headers.sh +4 -0
  707. package/src/targets/shell/httpie/fixtures/http-insecure.sh +1 -0
  708. package/src/targets/shell/httpie/fixtures/jsonObj-multiline.sh +5 -0
  709. package/src/targets/shell/httpie/fixtures/jsonObj-null-value.sh +3 -0
  710. package/src/targets/shell/httpie/fixtures/long-flags.sh +1 -0
  711. package/src/targets/shell/httpie/fixtures/multipart-data.sh +13 -0
  712. package/src/targets/shell/httpie/fixtures/multipart-file.sh +9 -0
  713. package/src/targets/shell/httpie/fixtures/multipart-form-data-no-params.sh +2 -0
  714. package/src/targets/shell/httpie/fixtures/multipart-form-data.sh +8 -0
  715. package/src/targets/shell/httpie/fixtures/nested.sh +1 -0
  716. package/src/targets/shell/httpie/fixtures/query-encoded.sh +1 -0
  717. package/src/targets/shell/httpie/fixtures/query.sh +1 -0
  718. package/src/targets/shell/httpie/fixtures/querystring-parameters.sh +1 -0
  719. package/src/targets/shell/httpie/fixtures/short-flags.sh +1 -0
  720. package/src/targets/shell/httpie/fixtures/short.sh +1 -0
  721. package/src/targets/shell/httpie/fixtures/text-plain.sh +3 -0
  722. package/src/targets/shell/httpie/fixtures/verbose-output.sh +1 -0
  723. package/src/targets/shell/target.ts +19 -0
  724. package/src/targets/shell/wget/client.test.ts +35 -0
  725. package/src/targets/shell/wget/client.ts +63 -0
  726. package/src/targets/shell/wget/fixtures/application-form-encoded.sh +6 -0
  727. package/src/targets/shell/wget/fixtures/application-json.sh +6 -0
  728. package/src/targets/shell/wget/fixtures/cookies.sh +5 -0
  729. package/src/targets/shell/wget/fixtures/custom-indentation.sh +8 -0
  730. package/src/targets/shell/wget/fixtures/custom-method.sh +4 -0
  731. package/src/targets/shell/wget/fixtures/full.sh +8 -0
  732. package/src/targets/shell/wget/fixtures/headers.sh +7 -0
  733. package/src/targets/shell/wget/fixtures/http-insecure.sh +4 -0
  734. package/src/targets/shell/wget/fixtures/jsonObj-multiline.sh +6 -0
  735. package/src/targets/shell/wget/fixtures/jsonObj-null-value.sh +6 -0
  736. package/src/targets/shell/wget/fixtures/multipart-data.sh +6 -0
  737. package/src/targets/shell/wget/fixtures/multipart-file.sh +6 -0
  738. package/src/targets/shell/wget/fixtures/multipart-form-data-no-params.sh +5 -0
  739. package/src/targets/shell/wget/fixtures/multipart-form-data.sh +6 -0
  740. package/src/targets/shell/wget/fixtures/nested.sh +4 -0
  741. package/src/targets/shell/wget/fixtures/query-encoded.sh +4 -0
  742. package/src/targets/shell/wget/fixtures/query.sh +4 -0
  743. package/src/targets/shell/wget/fixtures/short-options.sh +1 -0
  744. package/src/targets/shell/wget/fixtures/short.sh +4 -0
  745. package/src/targets/shell/wget/fixtures/text-plain.sh +6 -0
  746. package/src/targets/shell/wget/fixtures/v-output.sh +1 -0
  747. package/src/targets/shell/wget/fixtures/verbose-output.sh +1 -0
  748. package/src/targets/swift/helpers.ts +86 -0
  749. package/src/targets/swift/nsurlsession/client.test.ts +44 -0
  750. package/src/targets/swift/nsurlsession/client.ts +157 -0
  751. package/src/targets/swift/nsurlsession/fixtures/application-form-encoded.swift +25 -0
  752. package/src/targets/swift/nsurlsession/fixtures/application-json.swift +32 -0
  753. package/src/targets/swift/nsurlsession/fixtures/cookies.swift +21 -0
  754. package/src/targets/swift/nsurlsession/fixtures/custom-method.swift +18 -0
  755. package/src/targets/swift/nsurlsession/fixtures/full.swift +28 -0
  756. package/src/targets/swift/nsurlsession/fixtures/headers.swift +25 -0
  757. package/src/targets/swift/nsurlsession/fixtures/http-insecure.swift +18 -0
  758. package/src/targets/swift/nsurlsession/fixtures/indent-option.swift +18 -0
  759. package/src/targets/swift/nsurlsession/fixtures/json-null-value.swift +25 -0
  760. package/src/targets/swift/nsurlsession/fixtures/jsonObj-multiline.swift +25 -0
  761. package/src/targets/swift/nsurlsession/fixtures/jsonObj-null-value.swift +25 -0
  762. package/src/targets/swift/nsurlsession/fixtures/multipart-data.swift +56 -0
  763. package/src/targets/swift/nsurlsession/fixtures/multipart-file.swift +51 -0
  764. package/src/targets/swift/nsurlsession/fixtures/multipart-form-data-no-params.swift +21 -0
  765. package/src/targets/swift/nsurlsession/fixtures/multipart-form-data.swift +50 -0
  766. package/src/targets/swift/nsurlsession/fixtures/nested.swift +18 -0
  767. package/src/targets/swift/nsurlsession/fixtures/pretty-option.swift +24 -0
  768. package/src/targets/swift/nsurlsession/fixtures/query-encoded.swift +18 -0
  769. package/src/targets/swift/nsurlsession/fixtures/query.swift +18 -0
  770. package/src/targets/swift/nsurlsession/fixtures/short.swift +18 -0
  771. package/src/targets/swift/nsurlsession/fixtures/text-plain.swift +24 -0
  772. package/src/targets/swift/nsurlsession/fixtures/timeout-option.swift +18 -0
  773. package/src/targets/swift/target.ts +14 -0
  774. package/src/targets/targets.test.ts +297 -0
  775. package/src/targets/targets.ts +203 -0
  776. package/src/helpers/code-builder.js +0 -108
  777. package/src/helpers/headers.js +0 -48
  778. package/src/helpers/reducer.js +0 -20
  779. package/src/index.js +0 -361
  780. package/src/targets/c/index.js +0 -10
  781. package/src/targets/c/libcurl.js +0 -45
  782. package/src/targets/clojure/clj_http.js +0 -176
  783. package/src/targets/clojure/index.js +0 -10
  784. package/src/targets/csharp/httpclient.js +0 -157
  785. package/src/targets/csharp/index.js +0 -11
  786. package/src/targets/csharp/restsharp.js +0 -49
  787. package/src/targets/go/index.js +0 -10
  788. package/src/targets/go/native.js +0 -130
  789. package/src/targets/http/http1.1.js +0 -89
  790. package/src/targets/http/index.js +0 -10
  791. package/src/targets/index.js +0 -20
  792. package/src/targets/java/asynchttp.js +0 -54
  793. package/src/targets/java/index.js +0 -13
  794. package/src/targets/java/nethttp.js +0 -59
  795. package/src/targets/java/okhttp.js +0 -78
  796. package/src/targets/java/unirest.js +0 -57
  797. package/src/targets/javascript/axios.js +0 -101
  798. package/src/targets/javascript/fetch.js +0 -129
  799. package/src/targets/javascript/index.js +0 -13
  800. package/src/targets/javascript/jquery.js +0 -89
  801. package/src/targets/javascript/xhr.js +0 -86
  802. package/src/targets/kotlin/index.js +0 -10
  803. package/src/targets/kotlin/okhttp.js +0 -78
  804. package/src/targets/node/axios.js +0 -76
  805. package/src/targets/node/fetch.js +0 -145
  806. package/src/targets/node/index.js +0 -15
  807. package/src/targets/node/native.js +0 -92
  808. package/src/targets/node/request.js +0 -126
  809. package/src/targets/node/unirest.js +0 -120
  810. package/src/targets/objc/helpers.js +0 -80
  811. package/src/targets/objc/index.js +0 -10
  812. package/src/targets/objc/nsurlsession.js +0 -164
  813. package/src/targets/ocaml/cohttp.js +0 -73
  814. package/src/targets/ocaml/index.js +0 -10
  815. package/src/targets/php/curl.js +0 -142
  816. package/src/targets/php/guzzle.js +0 -135
  817. package/src/targets/php/helpers.js +0 -87
  818. package/src/targets/php/http1.js +0 -85
  819. package/src/targets/php/http2.js +0 -131
  820. package/src/targets/php/index.js +0 -14
  821. package/src/targets/powershell/common.js +0 -60
  822. package/src/targets/powershell/index.js +0 -11
  823. package/src/targets/powershell/restmethod.js +0 -8
  824. package/src/targets/powershell/webrequest.js +0 -8
  825. package/src/targets/python/helpers.js +0 -85
  826. package/src/targets/python/index.js +0 -11
  827. package/src/targets/python/requests.js +0 -163
  828. package/src/targets/r/httr.js +0 -137
  829. package/src/targets/r/index.js +0 -10
  830. package/src/targets/ruby/index.js +0 -10
  831. package/src/targets/ruby/native.js +0 -71
  832. package/src/targets/shell/curl.js +0 -157
  833. package/src/targets/shell/helpers.js +0 -23
  834. package/src/targets/shell/httpie.js +0 -129
  835. package/src/targets/shell/index.js +0 -13
  836. package/src/targets/shell/wget.js +0 -52
  837. package/src/targets/swift/helpers.js +0 -93
  838. package/src/targets/swift/index.js +0 -10
  839. package/src/targets/swift/nsurlsession.js +0 -152
package/src/index.ts ADDED
@@ -0,0 +1,361 @@
1
+ import type { Param, PostDataCommon, Request as NpmHarRequest } from 'har-format';
2
+ import type { UrlWithParsedQuery } from 'url';
3
+ import type { ReducedHelperObject } from './helpers/reducer';
4
+ import type { ClientId, TargetId } from './targets/targets';
5
+ import { map as eventStreamMap } from 'event-stream';
6
+ import FormData from 'form-data';
7
+ import { stringify as queryStringify } from 'qs';
8
+ // eslint-disable-next-line node/no-deprecated-api
9
+ import { format as urlFormat, parse as urlParse } from 'url';
10
+
11
+ import { formDataIterator, isBlob } from './helpers/form-data';
12
+ import { validateHarRequest } from './helpers/har-validator';
13
+ import { getHeaderName } from './helpers/headers';
14
+ import { reducer } from './helpers/reducer';
15
+ import { targets } from './targets/targets';
16
+
17
+ export { availableTargets, extname } from './helpers/utils';
18
+ export { addTarget, addTargetClient } from './targets/targets';
19
+
20
+ const DEBUG_MODE = false;
21
+
22
+ const debug = {
23
+ // eslint-disable-next-line @typescript-eslint/no-empty-function -- intentional noop
24
+ info: DEBUG_MODE ? console.info : () => {},
25
+ };
26
+
27
+ /** is this wrong? yes. according to the spec (http://www.softwareishard.com/blog/har-12-spec/#postData) it's technically wrong since `params` and `text` are (by the spec) mutually exclusive. However, in practice, this is not what is often the case.
28
+ *
29
+ * In general, this library takes a _descriptive_ rather than _perscriptive_ approach (see https://amyrey.web.unc.edu/classes/ling-101-online/tutorials/understanding-prescriptive-vs-descriptive-grammar/).
30
+ *
31
+ * Then, in addition to that, it really adds to complexity with TypeScript (TypeScript takes this constraint very very seriously) in a way that's not actually super useful. So, we treat this object as though it could have both or either of `params` and/or `text`.
32
+ */
33
+ type PostDataBase = PostDataCommon & {
34
+ text?: string;
35
+ params?: Param[];
36
+ };
37
+
38
+ export type HarRequest = Omit<NpmHarRequest, 'postData'> & { postData: PostDataBase };
39
+
40
+ export interface RequestExtras {
41
+ postData: PostDataBase & {
42
+ jsonObj?: ReducedHelperObject;
43
+ paramsObj?: ReducedHelperObject;
44
+ boundary?: string;
45
+ };
46
+ fullUrl: string;
47
+ queryObj: ReducedHelperObject;
48
+ headersObj: ReducedHelperObject;
49
+ uriObj: UrlWithParsedQuery;
50
+ cookiesObj: ReducedHelperObject;
51
+ allHeaders: ReducedHelperObject;
52
+ }
53
+
54
+ export type Request = HarRequest & RequestExtras;
55
+
56
+ interface Entry {
57
+ request: Partial<HarRequest>;
58
+ }
59
+
60
+ interface HarEntry {
61
+ log: {
62
+ version: string;
63
+ creator: {
64
+ name: string;
65
+ version: string;
66
+ };
67
+ entries: Entry[];
68
+ };
69
+ }
70
+
71
+ export interface HTTPSnippetOptions {
72
+ harIsAlreadyEncoded?: boolean;
73
+ }
74
+
75
+ const isHarEntry = (value: any): value is HarEntry =>
76
+ typeof value === 'object' &&
77
+ 'log' in value &&
78
+ typeof value.log === 'object' &&
79
+ 'entries' in value.log &&
80
+ Array.isArray(value.log.entries);
81
+
82
+ export class HTTPSnippet {
83
+ requests: Request[] = [];
84
+
85
+ constructor(input: HarEntry | HarRequest, opts: HTTPSnippetOptions = {}) {
86
+ let entries: Entry[] = [];
87
+
88
+ const options = {
89
+ harIsAlreadyEncoded: false,
90
+ ...opts,
91
+ };
92
+
93
+ // prep the main container
94
+ this.requests = [];
95
+
96
+ // is it har?
97
+ if (isHarEntry(input)) {
98
+ entries = input.log.entries;
99
+ } else {
100
+ entries = [
101
+ {
102
+ request: input,
103
+ },
104
+ ];
105
+ }
106
+
107
+ entries.forEach(({ request }) => {
108
+ // add optional properties to make validation successful
109
+ const req = {
110
+ bodySize: 0,
111
+ headersSize: 0,
112
+ headers: [],
113
+ cookies: [],
114
+ httpVersion: 'HTTP/1.1',
115
+ queryString: [],
116
+ postData: {
117
+ mimeType: request.postData?.mimeType || 'application/octet-stream',
118
+ },
119
+ ...request,
120
+ };
121
+
122
+ if (validateHarRequest(req)) {
123
+ this.requests.push(this.prepare(req, options));
124
+ }
125
+ });
126
+ }
127
+
128
+ prepare = (harRequest: HarRequest, options: HTTPSnippetOptions) => {
129
+ const request: Request = {
130
+ ...harRequest,
131
+ fullUrl: '',
132
+ uriObj: {} as UrlWithParsedQuery,
133
+ queryObj: {},
134
+ headersObj: {},
135
+ cookiesObj: {},
136
+ allHeaders: {},
137
+ };
138
+
139
+ // construct query objects
140
+ if (request.queryString && request.queryString.length) {
141
+ debug.info('queryString found, constructing queryString pair map');
142
+
143
+ request.queryObj = request.queryString.reduce(reducer, {});
144
+ }
145
+
146
+ // construct headers objects
147
+ if (request.headers && request.headers.length) {
148
+ const http2VersionRegex = /^HTTP\/2/;
149
+ request.headersObj = request.headers.reduce((accumulator, { name, value }) => {
150
+ const headerName = http2VersionRegex.exec(request.httpVersion) ? name.toLocaleLowerCase() : name;
151
+ return {
152
+ ...accumulator,
153
+ [headerName]: value,
154
+ };
155
+ }, {});
156
+ }
157
+
158
+ // construct headers objects
159
+ if (request.cookies && request.cookies.length) {
160
+ request.cookiesObj = request.cookies.reduceRight(
161
+ (accumulator, { name, value }) => ({
162
+ ...accumulator,
163
+ [name]: value,
164
+ }),
165
+ {}
166
+ );
167
+ }
168
+
169
+ // construct Cookie header
170
+ const cookies = request.cookies?.map(({ name, value }) => {
171
+ if (options.harIsAlreadyEncoded) {
172
+ return `${name}=${value}`;
173
+ }
174
+
175
+ return `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
176
+ });
177
+
178
+ if (cookies?.length) {
179
+ request.allHeaders.cookie = cookies.join('; ');
180
+ }
181
+
182
+ switch (request.postData.mimeType) {
183
+ case 'multipart/mixed':
184
+ case 'multipart/related':
185
+ case 'multipart/form-data':
186
+ case 'multipart/alternative':
187
+ // reset values
188
+ request.postData.text = '';
189
+ request.postData.mimeType = 'multipart/form-data';
190
+
191
+ if (request.postData?.params) {
192
+ const form = new FormData();
193
+
194
+ // The `form-data` module returns one of two things: a native FormData object, or its own polyfill
195
+ // Since the polyfill does not support the full API of the native FormData object, when this library is running in a browser environment it'll fail on two things:
196
+ //
197
+ // 1. The API for `form.append()` has three arguments and the third should only be present when the second is a
198
+ // Blob or USVString.
199
+ // 1. `FormData.pipe()` isn't a function.
200
+ //
201
+ // Since the native FormData object is iterable, we easily detect what version of `form-data` we're working with here to allow `multipart/form-data` requests to be compiled under both browser and Node environments.
202
+ //
203
+ // This hack is pretty awful but it's the only way we can use this library in the browser as if we code this against just the native FormData object, we can't polyfill that back into Node because Blob and File objects, which something like `formdata-polyfill` requires, don't exist there.
204
+ // @ts-expect-error TODO
205
+ const isNativeFormData = typeof form[Symbol.iterator] === 'function';
206
+
207
+ // TODO: THIS ABSOLUTELY MUST BE REMOVED.
208
+ // IT BREAKS SOME USE-CASES FOR MULTIPART FORMS THAT DEPEND ON BEING ABLE TO SET THE BOUNDARY.
209
+ // easter egg
210
+ const boundary = '---011000010111000001101001'; // this is binary for "api". yep.
211
+ if (!isNativeFormData) {
212
+ // @ts-expect-error THIS IS WRONG. VERY WRONG.
213
+ form._boundary = boundary;
214
+ }
215
+
216
+ request.postData?.params.forEach(param => {
217
+ const name = param.name;
218
+ const value = param.value || '';
219
+ const filename = param.fileName || null;
220
+
221
+ if (isNativeFormData) {
222
+ if (isBlob(value)) {
223
+ // @ts-expect-error TODO
224
+ form.append(name, value, filename);
225
+ } else {
226
+ form.append(name, value);
227
+ }
228
+ } else {
229
+ form.append(name, value, {
230
+ // @ts-expect-error TODO
231
+ filename,
232
+ // @ts-expect-error TODO
233
+ contentType: param.contentType || null,
234
+ });
235
+ }
236
+ });
237
+
238
+ if (isNativeFormData) {
239
+ // eslint-disable-next-line no-restricted-syntax
240
+ for (const data of formDataIterator(form, boundary)) {
241
+ request.postData.text += data;
242
+ }
243
+ } else {
244
+ form.pipe(
245
+ // @ts-expect-error TODO
246
+ eventStreamMap(data => {
247
+ request.postData.text += data;
248
+ })
249
+ );
250
+ }
251
+
252
+ request.postData.boundary = boundary;
253
+
254
+ // Since headers are case-sensitive we need to see if there's an existing `Content-Type` header that we can override.
255
+ const contentTypeHeader = getHeaderName(request.headersObj, 'content-type') || 'content-type';
256
+
257
+ request.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
258
+ }
259
+ break;
260
+
261
+ case 'application/x-www-form-urlencoded':
262
+ if (!request.postData.params) {
263
+ request.postData.text = '';
264
+ } else {
265
+ // @ts-expect-error the `har-format` types make this challenging
266
+ request.postData.paramsObj = request.postData.params.reduce(reducer, {});
267
+
268
+ // always overwrite
269
+ request.postData.text = queryStringify(request.postData.paramsObj);
270
+ }
271
+ break;
272
+
273
+ case 'text/json':
274
+ case 'text/x-json':
275
+ case 'application/json':
276
+ case 'application/x-json':
277
+ request.postData.mimeType = 'application/json';
278
+
279
+ if (request.postData.text) {
280
+ try {
281
+ request.postData.jsonObj = JSON.parse(request.postData.text);
282
+ } catch (e) {
283
+ debug.info(e);
284
+
285
+ // force back to `text/plain` if headers have proper content-type value, then this should also work
286
+ request.postData.mimeType = 'text/plain';
287
+ }
288
+ }
289
+ break;
290
+ }
291
+
292
+ // create allHeaders object
293
+ const allHeaders = {
294
+ ...request.allHeaders,
295
+ ...request.headersObj,
296
+ };
297
+
298
+ const urlWithParsedQuery = urlParse(request.url, true, true); //?
299
+
300
+ // query string key/value pairs in with literal querystrings containd within the url
301
+ request.queryObj = {
302
+ ...request.queryObj,
303
+ ...(urlWithParsedQuery.query as ReducedHelperObject),
304
+ }; //?
305
+
306
+ // reset uriObj values for a clean url
307
+ let search;
308
+ if (options.harIsAlreadyEncoded) {
309
+ search = queryStringify(request.queryObj, {
310
+ encode: false,
311
+ indices: false,
312
+ });
313
+ } else {
314
+ search = queryStringify(request.queryObj, {
315
+ indices: false,
316
+ });
317
+ }
318
+
319
+ const uriObj = {
320
+ ...urlWithParsedQuery,
321
+ query: request.queryObj,
322
+ search,
323
+ path: search ? `${urlWithParsedQuery.pathname}?${search}` : urlWithParsedQuery.pathname,
324
+ };
325
+
326
+ // keep the base url clean of queryString
327
+ const url = urlFormat({
328
+ ...urlWithParsedQuery,
329
+ query: null,
330
+ search: null,
331
+ }); //?
332
+
333
+ const fullUrl = urlFormat({
334
+ ...urlWithParsedQuery,
335
+ ...uriObj,
336
+ }); //?
337
+
338
+ return {
339
+ ...request,
340
+ allHeaders,
341
+ fullUrl,
342
+ url,
343
+ uriObj,
344
+ };
345
+ };
346
+
347
+ convert = (targetId: TargetId, clientId?: ClientId, options?: any) => {
348
+ if (!options && clientId) {
349
+ options = clientId;
350
+ }
351
+
352
+ const target = targets[targetId];
353
+ if (!target) {
354
+ return false;
355
+ }
356
+
357
+ const { convert } = target.clientsById[clientId || target.info.default];
358
+ const results = this.requests.map(request => convert(request, options));
359
+ return results.length === 1 ? results[0] : results;
360
+ };
361
+ }
@@ -0,0 +1,270 @@
1
+ /* eslint-disable jest/no-conditional-expect */
2
+ import type { Request } from '.';
3
+ import type { TargetId } from './targets/targets';
4
+ import type { Response } from 'har-format';
5
+
6
+ import shell from 'child_process';
7
+ import { format } from 'util';
8
+ import { readdirSync } from 'fs';
9
+ import path from 'path';
10
+
11
+ import { availableTargets, extname } from './helpers/utils';
12
+
13
+ const expectedBasePath = ['src', 'fixtures', 'requests'];
14
+
15
+ const ENVIRONMENT_CONFIG = {
16
+ docker: {
17
+ // Every client + target that we test in an HTTPBin-powered Docker environment.
18
+ node: ['axios', 'fetch', 'native', 'request'],
19
+ php: ['curl', 'guzzle'],
20
+ python: ['requests'],
21
+ shell: ['curl'],
22
+ },
23
+ local: {
24
+ // When running tests locally, or within a Jest CI environment, we shold limit the targets that
25
+ // we're testing so as to not require a mess of dependency requirements that would be better
26
+ // served within a container.
27
+ node: ['native'],
28
+ php: ['curl'],
29
+ python: ['requests'],
30
+ shell: ['curl'],
31
+ },
32
+ };
33
+
34
+ const inputFileNames = readdirSync(path.join(...expectedBasePath), 'utf-8');
35
+
36
+ const fixtures: [string, Request][] = inputFileNames.map(inputFileName => [
37
+ inputFileName.replace(path.extname(inputFileName), ''),
38
+ // eslint-disable-next-line import/no-dynamic-require, global-require
39
+ require(path.resolve(...expectedBasePath, inputFileName)),
40
+ ]);
41
+
42
+ /** ignore a set of fixtures from being run in tests */
43
+ const fixtureIgnoreFilter: string[] = [
44
+ // Some targets don't support native file handling without supplying a raw boundary header and
45
+ // because the HAR for `multipart-file` doesn't include the files contents, just its filename
46
+ // running one of these generated snippets doesn't send anything for the file because the
47
+ // FormData API rewrites the incoming full path of `src/fixtures/files/hello.txt` to just
48
+ // `hello.txt`. Instead of monkeypatching these targets to have the full file path at time ofb
49
+ // this execution suite we're just ignoring this test case as file uploading is well covered by
50
+ // the other cases we have.
51
+ 'multipart-file',
52
+ ];
53
+
54
+ const environmentFilter = (): string[] => {
55
+ if (process.env.HTTPBIN) {
56
+ return Object.keys(ENVIRONMENT_CONFIG.docker);
57
+ } else if (process.env.NODE_ENV === 'test') {
58
+ return Object.keys(ENVIRONMENT_CONFIG.local);
59
+ }
60
+
61
+ throw new Error('Unsupported environment supplied to `environmentFilter`.');
62
+ };
63
+
64
+ const clientFilter = (target: TargetId): string[] => {
65
+ if (process.env.HTTPBIN) {
66
+ // @ts-expect-error fix this type
67
+ return ENVIRONMENT_CONFIG.docker[target];
68
+ } else if (process.env.NODE_ENV === 'test') {
69
+ // @ts-expect-error fix this type
70
+ return ENVIRONMENT_CONFIG.local[target];
71
+ }
72
+
73
+ throw new Error('Unsupported environment supplied to `clientFilter`.');
74
+ };
75
+
76
+ const testFilter =
77
+ <T>(property: keyof T, list: T[keyof T][], ignore = false) =>
78
+ (item: T) => {
79
+ if (!list.length) {
80
+ return true;
81
+ } else if (ignore) {
82
+ return list.length > 0 ? !list.includes(item[property]) : true;
83
+ }
84
+
85
+ return list.length > 0 ? list.includes(item[property]) : true;
86
+ };
87
+
88
+ /**
89
+ * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!
90
+ */
91
+ function looseJSONParse(obj: any) {
92
+ // eslint-disable-next-line no-new-func
93
+ return new Function(`"use strict";return ${obj}`)();
94
+ }
95
+
96
+ availableTargets()
97
+ .filter(target => target.cli)
98
+ .filter(testFilter('key', environmentFilter()))
99
+ .forEach(({ key: targetId, cli: targetCLI, title, extname: fixtureExtension, clients }) => {
100
+ describe(`${title} integration tests`, () => {
101
+ clients.filter(testFilter('key', clientFilter(targetId))).forEach(({ key: clientId }) => {
102
+ // If we're in an HTTPBin-powered Docker environment we only want to run tests for the
103
+ // client that our Docker has been configured for.
104
+ if (process.env.HTTPBIN && process.env.INTEGRATION_CLIENT !== targetId) {
105
+ return;
106
+ }
107
+
108
+ // eslint-disable-next-line jest/valid-title
109
+ describe(clientId, () => {
110
+ fixtures.filter(testFilter(0, fixtureIgnoreFilter, true)).forEach(([fixture, request]) => {
111
+ it(`should return the expected response for \`${fixture}\``, () => {
112
+ const basePath = path.join(
113
+ 'src',
114
+ 'targets',
115
+ targetId,
116
+ clientId,
117
+ 'fixtures',
118
+ `${fixture}${extname(targetId)}`
119
+ );
120
+
121
+ // Clone the fixture we're testing against to another object because for multipart cases
122
+ // we're deleting the header, and if we don't clone the fixture to another object, that
123
+ // deleted header will cause other tests to fail because it's missing where other tests
124
+ // are expecting it.
125
+ const har = JSON.parse(JSON.stringify(request));
126
+ const url = har.log.entries[0].request.url;
127
+ const harResponse = har.log.entries[0].response as Response;
128
+
129
+ const command = format(targetCLI, basePath);
130
+ let stdout;
131
+ try {
132
+ stdout = shell.execSync(command);
133
+ } catch (err) {
134
+ // If this target throws errors when it can't access a method on the server that
135
+ // doesn't exist let's make sure that it only did that on the `custom-method` test,
136
+ // otherwise something went wrong!
137
+ if (err.message.includes('405 METHOD NOT ALLOWED')) {
138
+ expect(fixture).toBe('custom-method');
139
+ return;
140
+ }
141
+
142
+ throw err;
143
+ }
144
+
145
+ stdout = stdout.toString().trim();
146
+
147
+ // If the endpoint we're testing against returns HTML we should do a string comparison
148
+ // instead of parsing a non-existent JSON response.
149
+ if (harResponse.headers.find(header => header.name === 'Content-Type' && header.value === 'text/html')) {
150
+ // const stdoutTrimmed = stdout.toString().trim();
151
+
152
+ try {
153
+ expect(stdout).toStrictEqual(harResponse.content.text);
154
+ } catch (err) {
155
+ // Some targets always assume that their response is JSON and for this case
156
+ // (`custom-method`) will print out an empty string instead.
157
+ expect(stdout).toBe('');
158
+ }
159
+
160
+ return;
161
+ }
162
+
163
+ const expected = JSON.parse(String(harResponse.content.text));
164
+ let response;
165
+ try {
166
+ response = JSON.parse(stdout);
167
+ } catch (err) {
168
+ // Some JS targets print out their response with `console.log(json)` which creates
169
+ // a JSON object that we can't access with `JSON.parse()`.
170
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#never_use_eval!
171
+ if (fixtureExtension !== '.js') {
172
+ throw err;
173
+ }
174
+
175
+ response = looseJSONParse(stdout);
176
+ }
177
+
178
+ // If we're testing against the `/cookies` or `/headers` endpoints it returns a
179
+ // different schema than everything else.
180
+ if (url === 'https://httpbin.org/cookies') {
181
+ expect(response.cookies).toStrictEqual(expected.cookies);
182
+ return;
183
+ } else if (url === 'https://httpbin.org/headers') {
184
+ expect(response.headers).toStrictEqual(
185
+ expect.objectContaining({
186
+ ...expected.headers,
187
+ })
188
+ );
189
+
190
+ return;
191
+ }
192
+
193
+ expect(response.args).toStrictEqual(expected.args);
194
+
195
+ // Some targets send files that have a new line at the end of them without that new
196
+ // line so we need to make our assertion universal across all targets.
197
+ let files = {};
198
+ if (Object.keys(response.files).length) {
199
+ files = Object.entries(response.files)
200
+ .map(([k, v]) => ({ [k]: String(v).trim() }))
201
+ .reduce((prev, next) => Object.assign(prev, next));
202
+ }
203
+
204
+ expect(files).toStrictEqual(expected.files);
205
+
206
+ expect(response.form).toStrictEqual(expected.form);
207
+ expect(response.method).toStrictEqual(expected.method);
208
+ expect(response.url).toStrictEqual(expected.url);
209
+
210
+ // Because some JS targets may be returning their payloads with `console.log()` that
211
+ // method has a default depth, at which point it turns objects into `[Object]`. When
212
+ // we then run that through `looseJSONParse` it gets transformed again into
213
+ // `[ [Function: Object] ]`. Since we don't have access to the original object context
214
+ // from the target snippet, we rewrite our response a bit so that it can partially
215
+ // match what we're looking for.
216
+ //
217
+ // Of course the side effect to this is is that now these test cases may be subject
218
+ // to flakiness but without updating the root snippets to not use `console.log()`,
219
+ // which we don't want to do, this is the way it's got to be.
220
+ if (fixture === 'application-json' && fixtureExtension === '.js') {
221
+ const respJSON = response.json;
222
+ respJSON.arr_mix[2] = { arr_mix_nested: {} };
223
+
224
+ expect(respJSON).toStrictEqual(expected.json);
225
+ } else {
226
+ expect(response.json).toStrictEqual(expected.json);
227
+ }
228
+
229
+ // If we're dealing with a JSON payload, some snippets add indents and new lines to
230
+ // the data that is sent to
231
+ // HTTPBin (that it then returns back us in the same format) -- to make this `data`
232
+ // check target agnostic we need to parse and re-stringify our expectations so that
233
+ // this test can universally match them all.
234
+ if (expected.headers?.['Content-Type']?.includes('application/json')) {
235
+ expect(JSON.stringify(JSON.parse(response.data))).toStrictEqual(
236
+ JSON.stringify(JSON.parse(expected.data))
237
+ );
238
+ } else {
239
+ expect(response.data).toStrictEqual(expected.data);
240
+ }
241
+
242
+ // `multipart/form-data` needs some special tests to assert that boundaries were sent
243
+ // and received properly.
244
+ if (expected.headers?.['Content-Type']?.includes('multipart/form-data')) {
245
+ if (expected.headers['Content-Type'] === response.headers['Content-Type']) {
246
+ // If the headers match identically, great! If not we need to make sure that
247
+ // there's a boundary set up.
248
+ } else {
249
+ // It doesn't matter that the /right/ boundary is set up because some targets may
250
+ // add their own, we just need to make sure that **a** boundary is present.
251
+ const contentTypes: string[] = response.headers['Content-Type']
252
+ .split(';')
253
+ .map((p: string) => p.trim());
254
+
255
+ expect(contentTypes).toHaveLength(2);
256
+ expect(contentTypes.map(type => type.includes('boundary=')).filter(Boolean)).toHaveLength(1);
257
+ }
258
+ } else {
259
+ expect(response.headers).toStrictEqual(
260
+ expect.objectContaining({
261
+ ...expected.headers,
262
+ })
263
+ );
264
+ }
265
+ });
266
+ });
267
+ });
268
+ });
269
+ });
270
+ });
@@ -0,0 +1,50 @@
1
+ import type { Client } from '../../targets';
2
+ import { CodeBuilder } from '../../../helpers/code-builder';
3
+
4
+ export const libcurl: Client = {
5
+ info: {
6
+ key: 'libcurl',
7
+ title: 'Libcurl',
8
+ link: 'http://curl.haxx.se/libcurl',
9
+ description: 'Simple REST and HTTP API Client for C',
10
+ },
11
+ convert: ({ method, fullUrl, headersObj, allHeaders, postData }) => {
12
+ const { push, blank, join } = new CodeBuilder();
13
+
14
+ push('CURL *hnd = curl_easy_init();');
15
+ blank();
16
+ push(`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method.toUpperCase()}");`);
17
+ push(`curl_easy_setopt(hnd, CURLOPT_URL, "${fullUrl}");`);
18
+
19
+ // Add headers, including the cookies
20
+ const headers = Object.keys(headersObj);
21
+
22
+ // construct headers
23
+ if (headers.length) {
24
+ blank();
25
+ push('struct curl_slist *headers = NULL;');
26
+
27
+ headers.forEach(header => {
28
+ push(`headers = curl_slist_append(headers, "${header}: ${headersObj[header]}");`);
29
+ });
30
+
31
+ push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);');
32
+ }
33
+
34
+ // construct cookies
35
+ if (allHeaders.cookie) {
36
+ blank();
37
+ push(`curl_easy_setopt(hnd, CURLOPT_COOKIE, "${allHeaders.cookie}");`);
38
+ }
39
+
40
+ if (postData.text) {
41
+ blank();
42
+ push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${JSON.stringify(postData.text)});`);
43
+ }
44
+
45
+ blank();
46
+ push('CURLcode ret = curl_easy_perform(hnd);');
47
+
48
+ return join();
49
+ },
50
+ };
@@ -0,0 +1,12 @@
1
+ CURL *hnd = curl_easy_init();
2
+
3
+ curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
4
+ curl_easy_setopt(hnd, CURLOPT_URL, "https://httpbin.org/anything");
5
+
6
+ struct curl_slist *headers = NULL;
7
+ headers = curl_slist_append(headers, "content-type: application/x-www-form-urlencoded");
8
+ curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
9
+
10
+ curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "foo=bar&hello=world");
11
+
12
+ CURLcode ret = curl_easy_perform(hnd);