├── .editorconfig ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── bin └── httpsnippet ├── package.json ├── src ├── helpers │ ├── code-builder.js │ ├── index.js │ ├── reducer.js │ └── shell.js ├── index.js └── targets │ ├── c │ ├── index.js │ ├── info.js │ └── libcurl.js │ ├── csharp │ ├── index.js │ ├── info.js │ └── restsharp.js │ ├── go │ ├── index.js │ ├── info.js │ └── native.js │ ├── index.js │ ├── java │ ├── index.js │ ├── info.js │ ├── okhttp.js │ └── unirest.js │ ├── javascript │ ├── index.js │ ├── info.js │ ├── jquery.js │ └── xhr.js │ ├── node │ ├── index.js │ ├── info.js │ ├── native.js │ ├── request.js │ └── unirest.js │ ├── objc │ ├── helpers.js │ ├── index.js │ ├── info.js │ └── nsurlsession.js │ ├── ocaml │ ├── cohttp.js │ ├── index.js │ └── info.js │ ├── php │ ├── curl.js │ ├── helpers.js │ ├── http1.js │ ├── http2.js │ ├── index.js │ └── info.js │ ├── python │ ├── index.js │ ├── info.js │ ├── python3.js │ └── requests.js │ ├── ruby │ ├── index.js │ ├── info.js │ └── native.js │ ├── shell │ ├── curl.js │ ├── httpie.js │ ├── index.js │ ├── info.js │ └── wget.js │ └── swift │ ├── helpers.js │ ├── index.js │ ├── info.js │ └── nsurlsession.js └── test ├── fixtures ├── available-targets.json ├── cli.json ├── curl │ ├── http1.json │ └── index.js ├── files │ └── hello.txt ├── har.json ├── index.js ├── mimetypes.json ├── output │ ├── c │ │ └── libcurl │ │ │ ├── application-form-encoded.c │ │ │ ├── application-json.c │ │ │ ├── cookies.c │ │ │ ├── custom-method.c │ │ │ ├── full.c │ │ │ ├── headers.c │ │ │ ├── https.c │ │ │ ├── multipart-data.c │ │ │ ├── multipart-file.c │ │ │ ├── multipart-form-data.c │ │ │ ├── query.c │ │ │ ├── short.c │ │ │ └── text-plain.c │ ├── csharp │ │ └── restsharp │ │ │ ├── application-form-encoded.cs │ │ │ ├── application-json.cs │ │ │ ├── cookies.cs │ │ │ ├── custom-method.cs │ │ │ ├── full.cs │ │ │ ├── headers.cs │ │ │ ├── https.cs │ │ │ ├── multipart-data.cs │ │ │ ├── multipart-file.cs │ │ │ ├── multipart-form-data.cs │ │ │ ├── query.cs │ │ │ ├── short.cs │ │ │ └── text-plain.cs │ ├── go │ │ └── native │ │ │ ├── application-form-encoded.go │ │ │ ├── application-json.go │ │ │ ├── cookies.go │ │ │ ├── custom-method.go │ │ │ ├── full.go │ │ │ ├── headers.go │ │ │ ├── https.go │ │ │ ├── multipart-data.go │ │ │ ├── multipart-file.go │ │ │ ├── multipart-form-data.go │ │ │ ├── query.go │ │ │ ├── short.go │ │ │ └── text-plain.go │ ├── java │ │ ├── okhttp │ │ │ ├── application-form-encoded.java │ │ │ ├── application-json.java │ │ │ ├── cookies.java │ │ │ ├── custom-method.java │ │ │ ├── full.java │ │ │ ├── headers.java │ │ │ ├── https.java │ │ │ ├── multipart-data.java │ │ │ ├── multipart-file.java │ │ │ ├── multipart-form-data.java │ │ │ ├── query.java │ │ │ ├── short.java │ │ │ └── text-plain.java │ │ └── unirest │ │ │ ├── application-form-encoded.java │ │ │ ├── application-json.java │ │ │ ├── cookies.java │ │ │ ├── custom-method.java │ │ │ ├── full.java │ │ │ ├── headers.java │ │ │ ├── https.java │ │ │ ├── multipart-data.java │ │ │ ├── multipart-file.java │ │ │ ├── multipart-form-data.java │ │ │ ├── query.java │ │ │ ├── short.java │ │ │ └── text-plain.java │ ├── javascript │ │ ├── jquery │ │ │ ├── application-form-encoded.js │ │ │ ├── application-json.js │ │ │ ├── cookies.js │ │ │ ├── custom-method.js │ │ │ ├── full.js │ │ │ ├── headers.js │ │ │ ├── https.js │ │ │ ├── multipart-data.js │ │ │ ├── multipart-file.js │ │ │ ├── multipart-form-data.js │ │ │ ├── query.js │ │ │ ├── short.js │ │ │ └── text-plain.js │ │ └── xhr │ │ │ ├── application-form-encoded.js │ │ │ ├── application-json.js │ │ │ ├── cookies.js │ │ │ ├── custom-method.js │ │ │ ├── full.js │ │ │ ├── headers.js │ │ │ ├── https.js │ │ │ ├── multipart-data.js │ │ │ ├── multipart-file.js │ │ │ ├── multipart-form-data.js │ │ │ ├── query.js │ │ │ ├── short.js │ │ │ └── text-plain.js │ ├── node │ │ ├── native │ │ │ ├── application-form-encoded.js │ │ │ ├── application-json.js │ │ │ ├── cookies.js │ │ │ ├── custom-method.js │ │ │ ├── full.js │ │ │ ├── headers.js │ │ │ ├── https.js │ │ │ ├── multipart-data.js │ │ │ ├── multipart-file.js │ │ │ ├── multipart-form-data.js │ │ │ ├── query.js │ │ │ ├── short.js │ │ │ └── text-plain.js │ │ ├── request │ │ │ ├── application-form-encoded.js │ │ │ ├── application-json.js │ │ │ ├── cookies.js │ │ │ ├── custom-method.js │ │ │ ├── full.js │ │ │ ├── headers.js │ │ │ ├── https.js │ │ │ ├── multipart-data.js │ │ │ ├── multipart-file.js │ │ │ ├── multipart-form-data.js │ │ │ ├── query.js │ │ │ ├── short.js │ │ │ └── text-plain.js │ │ └── unirest │ │ │ ├── application-form-encoded.js │ │ │ ├── application-json.js │ │ │ ├── cookies.js │ │ │ ├── custom-method.js │ │ │ ├── full.js │ │ │ ├── headers.js │ │ │ ├── https.js │ │ │ ├── multipart-data.js │ │ │ ├── multipart-file.js │ │ │ ├── multipart-form-data.js │ │ │ ├── query.js │ │ │ ├── short.js │ │ │ └── text-plain.js │ ├── objc │ │ └── nsurlsession │ │ │ ├── application-form-encoded.m │ │ │ ├── application-json.m │ │ │ ├── cookies.m │ │ │ ├── custom-method.m │ │ │ ├── full.m │ │ │ ├── headers.m │ │ │ ├── https.m │ │ │ ├── multipart-data.m │ │ │ ├── multipart-file.m │ │ │ ├── multipart-form-data.m │ │ │ ├── query.m │ │ │ ├── short.m │ │ │ └── text-plain.m │ ├── ocaml │ │ └── cohttp │ │ │ ├── application-form-encoded.ml │ │ │ ├── application-json.ml │ │ │ ├── cookies.ml │ │ │ ├── custom-method.ml │ │ │ ├── full.ml │ │ │ ├── headers.ml │ │ │ ├── https.ml │ │ │ ├── multipart-data.ml │ │ │ ├── multipart-file.ml │ │ │ ├── multipart-form-data.ml │ │ │ ├── query.ml │ │ │ ├── short.ml │ │ │ └── text-plain.ml │ ├── php │ │ ├── curl │ │ │ ├── application-form-encoded.php │ │ │ ├── application-json.php │ │ │ ├── cookies.php │ │ │ ├── custom-method.php │ │ │ ├── full.php │ │ │ ├── headers.php │ │ │ ├── https.php │ │ │ ├── multipart-data.php │ │ │ ├── multipart-file.php │ │ │ ├── multipart-form-data.php │ │ │ ├── query.php │ │ │ ├── short.php │ │ │ └── text-plain.php │ │ ├── http1 │ │ │ ├── application-form-encoded.php │ │ │ ├── application-json.php │ │ │ ├── cookies.php │ │ │ ├── custom-method.php │ │ │ ├── full.php │ │ │ ├── headers.php │ │ │ ├── https.php │ │ │ ├── multipart-data.php │ │ │ ├── multipart-file.php │ │ │ ├── multipart-form-data.php │ │ │ ├── query.php │ │ │ ├── short.php │ │ │ └── text-plain.php │ │ └── http2 │ │ │ ├── application-form-encoded.php │ │ │ ├── application-json.php │ │ │ ├── cookies.php │ │ │ ├── custom-method.php │ │ │ ├── full.php │ │ │ ├── headers.php │ │ │ ├── https.php │ │ │ ├── multipart-data.php │ │ │ ├── multipart-file.php │ │ │ ├── multipart-form-data.php │ │ │ ├── query.php │ │ │ ├── short.php │ │ │ └── text-plain.php │ ├── python │ │ ├── python3 │ │ │ ├── application-form-encoded.py │ │ │ ├── application-json.py │ │ │ ├── cookies.py │ │ │ ├── custom-method.py │ │ │ ├── full.py │ │ │ ├── headers.py │ │ │ ├── https.py │ │ │ ├── multipart-data.py │ │ │ ├── multipart-file.py │ │ │ ├── multipart-form-data.py │ │ │ ├── query.py │ │ │ ├── short.py │ │ │ └── text-plain.py │ │ └── requests │ │ │ ├── application-form-encoded.py │ │ │ ├── application-json.py │ │ │ ├── cookies.py │ │ │ ├── custom-method.py │ │ │ ├── full.py │ │ │ ├── headers.py │ │ │ ├── https.py │ │ │ ├── multipart-data.py │ │ │ ├── multipart-file.py │ │ │ ├── multipart-form-data.py │ │ │ ├── query.py │ │ │ ├── short.py │ │ │ └── text-plain.py │ ├── ruby │ │ └── native │ │ │ ├── application-form-encoded.rb │ │ │ ├── application-json.rb │ │ │ ├── cookies.rb │ │ │ ├── custom-method.rb │ │ │ ├── full.rb │ │ │ ├── headers.rb │ │ │ ├── https.rb │ │ │ ├── multipart-data.rb │ │ │ ├── multipart-file.rb │ │ │ ├── multipart-form-data.rb │ │ │ ├── query.rb │ │ │ ├── short.rb │ │ │ └── text-plain.rb │ ├── shell │ │ ├── curl │ │ │ ├── application-form-encoded.sh │ │ │ ├── application-json.sh │ │ │ ├── cookies.sh │ │ │ ├── custom-method.sh │ │ │ ├── full.sh │ │ │ ├── headers.sh │ │ │ ├── http1.sh │ │ │ ├── https.sh │ │ │ ├── multipart-data.sh │ │ │ ├── multipart-file.sh │ │ │ ├── multipart-form-data.sh │ │ │ ├── query.sh │ │ │ ├── short.sh │ │ │ └── text-plain.sh │ │ ├── httpie │ │ │ ├── application-form-encoded.sh │ │ │ ├── application-json.sh │ │ │ ├── cookies.sh │ │ │ ├── custom-method.sh │ │ │ ├── full.sh │ │ │ ├── headers.sh │ │ │ ├── https.sh │ │ │ ├── multipart-data.sh │ │ │ ├── multipart-file.sh │ │ │ ├── multipart-form-data.sh │ │ │ ├── query.sh │ │ │ ├── short.sh │ │ │ └── text-plain.sh │ │ └── wget │ │ │ ├── application-form-encoded.sh │ │ │ ├── application-json.sh │ │ │ ├── cookies.sh │ │ │ ├── custom-method.sh │ │ │ ├── full.sh │ │ │ ├── headers.sh │ │ │ ├── https.sh │ │ │ ├── multipart-data.sh │ │ │ ├── multipart-file.sh │ │ │ ├── multipart-form-data.sh │ │ │ ├── query.sh │ │ │ ├── short.sh │ │ │ └── text-plain.sh │ └── swift │ │ └── nsurlsession │ │ ├── application-form-encoded.swift │ │ ├── application-json.swift │ │ ├── cookies.swift │ │ ├── custom-method.swift │ │ ├── full.swift │ │ ├── headers.swift │ │ ├── https.swift │ │ ├── multipart-data.swift │ │ ├── multipart-file.swift │ │ ├── multipart-form-data.swift │ │ ├── query.swift │ │ ├── short.swift │ │ └── text-plain.swift └── requests │ ├── application-form-encoded.json │ ├── application-json.json │ ├── cookies.json │ ├── custom-method.json │ ├── full.json │ ├── headers.json │ ├── https.json │ ├── index.js │ ├── multipart-data.json │ ├── multipart-file.json │ ├── multipart-form-data.json │ ├── query.json │ ├── short.json │ └── text-plain.json ├── helpers.js ├── index.js ├── requests.js ├── targets.js └── tests ├── c ├── index.js └── libcurl.js ├── csharp ├── index.js └── restsharp.js ├── go ├── index.js └── native.js ├── index.js ├── java ├── index.js ├── okhttp.js └── unirest.js ├── javascript ├── jquery.js └── xhr.js ├── node ├── index.js ├── native.js ├── request.js └── unirest.js ├── objc ├── index.js └── nsurlsession.js ├── ocaml ├── cohttp.js └── index.js ├── php ├── curl.js ├── http1.js ├── http2.js └── index.js ├── python ├── index.js ├── python3.js └── requests.js ├── ruby ├── index.js └── native.js ├── shell ├── curl.js ├── httpie.js ├── index.js └── wget.js └── swift ├── index.js └── nsurlsession.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "asi": true, 3 | "node": true 4 | } 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .jshintrc 2 | .editorconfig 3 | test 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - iojs 5 | - 0.10 6 | - 0.11 7 | - 0.12 8 | 9 | script: npm run travis 10 | 11 | before_install: 12 | - sudo apt-get update -qq 13 | - sudo apt-get install -qq --yes python3 php5-curl php5-cli 14 | 15 | after_script: 16 | - npm run coverage 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Mashape (https://www.mashape.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.16.21", 3 | "name": "httpsnippet-fsless", 4 | "description": "HTTP Request snippet generator for *most* languages without using node-fs", 5 | "author": "Abhijit Kane, abhijit@getpostman.com", 6 | "homepage": "https://github.com/postmanlabs/httpsnippet", 7 | "license": "MIT", 8 | "main": "./src/index.js", 9 | "bin": "./bin/httpsnippet", 10 | "keywords": [ 11 | "api", 12 | "csharp", 13 | "curl", 14 | "go", 15 | "har", 16 | "http", 17 | "httpie", 18 | "java", 19 | "javascript", 20 | "jquery", 21 | "objc", 22 | "objective-c", 23 | "ocaml", 24 | "php", 25 | "python", 26 | "request", 27 | "requests", 28 | "ruby", 29 | "shell", 30 | "snippet", 31 | "swift", 32 | "swift", 33 | "unirest", 34 | "xhr", 35 | "xmlhttprequest" 36 | ], 37 | "engines": { 38 | "node": ">=0.10" 39 | }, 40 | "files": [ 41 | "bin", 42 | "src" 43 | ], 44 | "repository": { 45 | "type": "git", 46 | "url": "https://github.com/postmanlabs/httpsnippet" 47 | }, 48 | "bugs": { 49 | "url": "https://github.com/postmanlabs/httpsnippet/issues" 50 | }, 51 | "scripts": { 52 | "test": "mocha --no-timeouts --reporter spec --fgrep 'Request Validation' --invert", 53 | "travis": "mocha --no-timeouts --reporter spec", 54 | "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --fgrep 'Request Validation' --invert", 55 | "codeclimate": "codeclimate < coverage/lcov.info" 56 | }, 57 | "devDependencies": { 58 | "glob": "^5.0.3", 59 | "istanbul": "0.4.5", 60 | "mocha": "^4.0.0", 61 | "should": "^5.2.0" 62 | }, 63 | "dependencies": { 64 | "async": "^0.9.0", 65 | "chalk": "^1.0.0", 66 | "commander": "^2.7.1", 67 | "debug": "^2.1.3", 68 | "event-stream": "3.3.4", 69 | "folderify": "^0.7.0", 70 | "form-data": "^0.2.0", 71 | "har-validator-fsless": "1.6.6", 72 | "postman-collection": "3.0.8" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/helpers/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "code-builder": require('./code-builder.js'), 5 | "reducer": require('./reducer.js'), 6 | "shell": require('./shell.js') 7 | } 8 | 9 | -------------------------------------------------------------------------------- /src/helpers/reducer.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (obj, pair) { 4 | if (obj[pair.name] === undefined) { 5 | obj[pair.name] = pair.value 6 | return obj 7 | } 8 | 9 | if(obj[pair.name] instanceof Array) { 10 | obj[pair.name].push(pair.value) 11 | return obj 12 | } 13 | 14 | // convert to array 15 | var arr = [ 16 | obj[pair.name], 17 | pair.value 18 | ] 19 | 20 | obj[pair.name] = arr 21 | 22 | return obj 23 | } 24 | -------------------------------------------------------------------------------- /src/helpers/shell.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var util = require('util') 4 | 5 | module.exports = { 6 | /** 7 | * Use 'strong quoting' using single quotes so that we only need 8 | * to deal with nested single quote characters. 9 | * http://wiki.bash-hackers.org/syntax/quoting#strong_quoting 10 | */ 11 | quote: function (value) { 12 | var safe = /^[a-z0-9-_/.@%^=:]+$/i 13 | 14 | // Unless `value` is a simple shell-safe string, quote it. 15 | if (!safe.test(value)) { 16 | return util.format('\'%s\'', value.replace(/'/g, "\'\\'\'")) 17 | } 18 | 19 | return value 20 | }, 21 | 22 | escape: function (value) { 23 | return value.replace(/\r/g, '\\r').replace(/\n/g, '\\n') 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/targets/c/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "libcurl": require('./libcurl.js') 6 | } 7 | -------------------------------------------------------------------------------- /src/targets/c/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'c', 5 | title: 'C', 6 | extname: '.c', 7 | default: 'libcurl' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/c/libcurl.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var CodeBuilder = require('../../helpers/code-builder') 4 | 5 | module.exports = function (source, options) { 6 | var code = new CodeBuilder() 7 | 8 | code.push('CURL *hnd = curl_easy_init();') 9 | .blank() 10 | .push('curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "%s");', source.method.toUpperCase()) 11 | .push('curl_easy_setopt(hnd, CURLOPT_URL, "%s");', source.fullUrl) 12 | 13 | // Add headers, including the cookies 14 | var headers = Object.keys(source.headersObj) 15 | 16 | // construct headers 17 | if (headers.length) { 18 | code.blank() 19 | .push('struct curl_slist *headers = NULL;') 20 | 21 | headers.map(function (key) { 22 | code.push('headers = curl_slist_append(headers, "%s: %s");', key, source.headersObj[key]) 23 | }) 24 | 25 | code.push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);') 26 | } 27 | 28 | // construct cookies 29 | if (source.allHeaders.cookie) { 30 | code.blank() 31 | .push('curl_easy_setopt(hnd, CURLOPT_COOKIE, "%s");', source.allHeaders.cookie) 32 | } 33 | 34 | if (source.postData.text) { 35 | code.blank() 36 | .push('curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, %s);', JSON.stringify(source.postData.text)) 37 | } 38 | 39 | code.blank() 40 | .push('CURLcode ret = curl_easy_perform(hnd);') 41 | 42 | return code.join() 43 | } 44 | 45 | module.exports.info = { 46 | key: 'libcurl', 47 | title: 'Libcurl', 48 | link: 'http://curl.haxx.se/libcurl/', 49 | description: 'Simple REST and HTTP API Client for C' 50 | } 51 | -------------------------------------------------------------------------------- /src/targets/csharp/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "restsharp": require('./restsharp.js') 6 | } 7 | -------------------------------------------------------------------------------- /src/targets/csharp/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'csharp', 5 | title: 'C#', 6 | extname: '.cs', 7 | default: 'restsharp' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/csharp/restsharp.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var CodeBuilder = require('../../helpers/code-builder') 4 | 5 | module.exports = function (source, options) { 6 | var code = new CodeBuilder() 7 | var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS' ] 8 | 9 | if (methods.indexOf(source.method.toUpperCase()) === -1) { 10 | return 'Method not supported' 11 | } else { 12 | code.push('var client = new RestClient("%s");', source.fullUrl) 13 | code.push('var request = new RestRequest(Method.%s);', source.method.toUpperCase()) 14 | } 15 | 16 | // Add headers, including the cookies 17 | var headers = Object.keys(source.headersObj) 18 | 19 | // construct headers 20 | if (headers.length) { 21 | headers.map(function (key) { 22 | code.push('request.AddHeader("%s", "%s");', key, source.headersObj[key]) 23 | }) 24 | } 25 | 26 | // construct cookies 27 | if (source.cookies.length) { 28 | source.cookies.forEach(function (cookie) { 29 | code.push('request.AddCookie("%s", "%s");', cookie.name, cookie.value) 30 | }) 31 | } 32 | 33 | if (source.postData.text) { 34 | code.push('request.AddParameter("%s", %s, ParameterType.RequestBody);', source.allHeaders['content-type'], JSON.stringify(source.postData.text)) 35 | } 36 | 37 | code.push('IRestResponse response = client.Execute(request);') 38 | return code.join() 39 | } 40 | 41 | module.exports.info = { 42 | key: 'restsharp', 43 | title: 'RestSharp', 44 | link: 'http://restsharp.org/', 45 | description: 'Simple REST and HTTP API Client for .NET' 46 | } 47 | -------------------------------------------------------------------------------- /src/targets/go/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "native": require('./native.js') 6 | } 7 | -------------------------------------------------------------------------------- /src/targets/go/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'go', 5 | title: 'Go', 6 | extname: '.go', 7 | default: 'native' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/java/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "okhttp": require('./okhttp.js'), 6 | "unirest": require('./unirest.js') 7 | } 8 | -------------------------------------------------------------------------------- /src/targets/java/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'java', 5 | title: 'Java', 6 | extname: '.java', 7 | default: 'unirest' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/java/unirest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description 3 | * HTTP code snippet generator for Java using Unirest. 4 | * 5 | * @author 6 | * @shashiranjan84 7 | * 8 | * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author. 9 | */ 10 | 11 | 'use strict' 12 | 13 | var util = require('util') 14 | var CodeBuilder = require('../../helpers/code-builder') 15 | 16 | module.exports = function (source, options) { 17 | var opts = util._extend({ 18 | indent: ' ' 19 | }, options) 20 | 21 | var code = new CodeBuilder(opts.indent) 22 | 23 | var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS' ] 24 | 25 | if (methods.indexOf(source.method.toUpperCase()) === -1) { 26 | code.push('HttpResponse response = Unirest.customMethod("%s","%s")', source.method.toUpperCase(), source.fullUrl) 27 | } else { 28 | code.push('HttpResponse response = Unirest.%s("%s")', source.method.toLowerCase(), source.fullUrl) 29 | } 30 | 31 | // Add headers, including the cookies 32 | var headers = Object.keys(source.allHeaders) 33 | 34 | // construct headers 35 | if (headers.length) { 36 | headers.map(function (key) { 37 | code.push(1, '.header("%s", "%s")', key, source.allHeaders[key]) 38 | }) 39 | } 40 | 41 | if (source.postData.text) { 42 | code.push(1, '.body(%s)', JSON.stringify(source.postData.text)) 43 | } 44 | 45 | code.push(1, '.asString();') 46 | 47 | return code.join() 48 | } 49 | 50 | module.exports.info = { 51 | key: 'unirest', 52 | title: 'Unirest', 53 | link: 'http://unirest.io/java.html', 54 | description: 'Lightweight HTTP Request Client Library' 55 | } 56 | -------------------------------------------------------------------------------- /src/targets/javascript/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "jquery": require('./jquery.js'), 6 | "xhr": require('./xhr.js') 7 | } 8 | -------------------------------------------------------------------------------- /src/targets/javascript/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'javascript', 5 | title: 'JavaScript', 6 | extname: '.js', 7 | default: 'xhr' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "native": require('./native.js'), 6 | "request": require('./request.js'), 7 | "unirest": require('./unirest.js') 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/node/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'node', 5 | title: 'Node.js', 6 | extname: '.js', 7 | default: 'native' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/objc/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "helpers": require('./helpers.js'), 6 | "nsurlsession": require('./nsurlsession.js') 7 | } 8 | -------------------------------------------------------------------------------- /src/targets/objc/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'objc', 5 | title: 'Objective-C', 6 | extname: '.m', 7 | default: 'nsurlsession' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/ocaml/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "cohttp": require('./cohttp.js') 6 | } 7 | 8 | -------------------------------------------------------------------------------- /src/targets/ocaml/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'ocaml', 5 | title: 'OCaml', 6 | extname: '.ml', 7 | default: 'cohttp' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/php/helpers.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var convert = function (obj, indent, last_indent) { 4 | var i, result 5 | 6 | if (!last_indent) { 7 | last_indent = '' 8 | } 9 | 10 | switch (Object.prototype.toString.call(obj)) { 11 | case '[object Null]': 12 | result = 'null' 13 | break 14 | 15 | case '[object Undefined]': 16 | result = 'null' 17 | break 18 | 19 | case '[object String]': 20 | result = "'" + obj.replace(/\\/g, '\\\\').replace(/\'/g, "\'") + "'" 21 | break 22 | 23 | case '[object Number]': 24 | result = obj.toString() 25 | break 26 | 27 | case '[object Array]': 28 | result = [] 29 | 30 | obj.map(function (item) { 31 | result.push(convert(item, indent + indent, indent)) 32 | }) 33 | 34 | result = 'array(\n' + indent + result.join(',\n' + indent) + '\n' + last_indent + ')' 35 | break 36 | 37 | case '[object Object]': 38 | result = [] 39 | for (i in obj) { 40 | if (obj.hasOwnProperty(i)) { 41 | result.push(convert(i, indent) + ' => ' + convert(obj[i], indent + indent, indent)) 42 | } 43 | } 44 | result = 'array(\n' + indent + result.join(',\n' + indent) + '\n' + last_indent + ')' 45 | break 46 | 47 | default: 48 | result = 'null' 49 | } 50 | 51 | return result 52 | } 53 | 54 | module.exports = { 55 | convert: convert, 56 | methods: [ 57 | 'ACL', 58 | 'BASELINE_CONTROL', 59 | 'CHECKIN', 60 | 'CHECKOUT', 61 | 'CONNECT', 62 | 'COPY', 63 | 'DELETE', 64 | 'GET', 65 | 'HEAD', 66 | 'LABEL', 67 | 'LOCK', 68 | 'MERGE', 69 | 'MKACTIVITY', 70 | 'MKCOL', 71 | 'MKWORKSPACE', 72 | 'MOVE', 73 | 'OPTIONS', 74 | 'POST', 75 | 'PROPFIND', 76 | 'PROPPATCH', 77 | 'PUT', 78 | 'REPORT', 79 | 'TRACE', 80 | 'UNCHECKOUT', 81 | 'UNLOCK', 82 | 'UPDATE', 83 | 'VERSION_CONTROL' 84 | ] 85 | } 86 | -------------------------------------------------------------------------------- /src/targets/php/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "curl": require('./curl.js'), 6 | "helpers": require('./helpers.js'), 7 | "http1": require('./http1.js'), 8 | "http2": require('./http2.js'), 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/targets/php/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'php', 5 | title: 'PHP', 6 | extname: '.php', 7 | default: 'curl' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/python/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "python3": require('./python3.js'), 6 | "requests": require('./requests.js') 7 | } 8 | -------------------------------------------------------------------------------- /src/targets/python/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'python', 5 | title: 'Python', 6 | extname: '.py', 7 | default: 'python3' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/ruby/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "native": require('./native.js') 6 | } 7 | -------------------------------------------------------------------------------- /src/targets/ruby/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'ruby', 5 | title: 'Ruby', 6 | extname: '.rb', 7 | default: 'native' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/ruby/native.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var CodeBuilder = require('../../helpers/code-builder') 4 | 5 | module.exports = function (source, options) { 6 | var code = new CodeBuilder() 7 | 8 | code.push('require \'uri\'') 9 | .push('require \'net/http\'') 10 | .blank() 11 | 12 | // To support custom methods we check for the supported methods 13 | // and if doesn't exist then we build a custom class for it 14 | var method = source.method.toUpperCase() 15 | var methods = ['GET', 'POST', 'HEAD', 'DELETE', 'PATCH', 'PUT', 'OPTIONS', 'COPY', 'LOCK', 'UNLOCK', 'MOVE', 'TRACE'] 16 | var capMethod = method.charAt(0) + method.substring(1).toLowerCase() 17 | if (methods.indexOf(method) < 0) { 18 | code.push('class Net::HTTP::%s < Net::HTTPRequest', capMethod) 19 | .push(' METHOD = \'%s\'', method.toUpperCase()) 20 | .push(' REQUEST_HAS_BODY = \'%s\'', source.postData.text ? 'true' : 'false') 21 | .push(' RESPONSE_HAS_BODY = true') 22 | .push('end') 23 | .blank() 24 | } 25 | 26 | code.push('url = URI("%s")', source.fullUrl) 27 | .blank() 28 | .push('http = Net::HTTP.new(url.host, url.port)') 29 | 30 | if (source.uriObj.protocol === 'https:') { 31 | code.push('http.use_ssl = true') 32 | .push('http.verify_mode = OpenSSL::SSL::VERIFY_NONE') 33 | } 34 | 35 | code.blank() 36 | .push('request = Net::HTTP::%s.new(url)', capMethod) 37 | 38 | var headers = Object.keys(source.allHeaders) 39 | if (headers.length) { 40 | headers.map(function (key) { 41 | code.push('request["%s"] = \'%s\'', key, source.allHeaders[key]) 42 | }) 43 | } 44 | 45 | if (source.postData.text) { 46 | code.push('request.body = %s', JSON.stringify(source.postData.text)) 47 | } 48 | 49 | code.blank() 50 | .push('response = http.request(request)') 51 | .push('puts response.read_body') 52 | 53 | return code.join() 54 | } 55 | 56 | module.exports.info = { 57 | key: 'native', 58 | title: 'net::http', 59 | link: 'http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html', 60 | description: 'Ruby HTTP client' 61 | } 62 | -------------------------------------------------------------------------------- /src/targets/shell/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "curl": require('./curl.js'), 6 | "httpie": require('./httpie.js'), 7 | "wget": require('./wget.js') 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/shell/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'shell', 5 | title: 'Shell', 6 | extname: '.sh', 7 | default: 'curl' 8 | } 9 | -------------------------------------------------------------------------------- /src/targets/shell/wget.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description 3 | * HTTP code snippet generator for the Shell using Wget. 4 | * 5 | * @author 6 | * @AhmadNassri 7 | * 8 | * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author. 9 | */ 10 | 11 | 'use strict' 12 | 13 | var util = require('util') 14 | var helpers = require('../../helpers/shell') 15 | var CodeBuilder = require('../../helpers/code-builder') 16 | 17 | module.exports = function (source, options) { 18 | var opts = util._extend({ 19 | indent: ' ', 20 | short: false, 21 | verbose: false 22 | }, options) 23 | 24 | var code = new CodeBuilder(opts.indent, opts.indent !== false ? ' \\\n' + opts.indent : ' ') 25 | 26 | if (opts.verbose) { 27 | code.push('wget %s', opts.short ? '-v' : '--verbose') 28 | } else { 29 | code.push('wget %s', opts.short ? '-q' : '--quiet') 30 | } 31 | 32 | code.push('--method %s', helpers.quote(source.method)) 33 | 34 | Object.keys(source.allHeaders).map(function (key) { 35 | var header = util.format('%s: %s', key, source.allHeaders[key]) 36 | code.push('--header %s', helpers.quote(header)) 37 | }) 38 | 39 | if (source.postData.text) { 40 | code.push('--body-data ' + helpers.escape(helpers.quote(source.postData.text))) 41 | } 42 | 43 | code.push(opts.short ? '-O' : '--output-document') 44 | .push('- %s', helpers.quote(source.fullUrl)) 45 | 46 | return code.join() 47 | } 48 | 49 | module.exports.info = { 50 | key: 'wget', 51 | title: 'Wget', 52 | link: 'https://www.gnu.org/software/wget/', 53 | description: 'a free software package for retrieving files using HTTP, HTTPS' 54 | } 55 | -------------------------------------------------------------------------------- /src/targets/swift/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | "info": require('./info.js'), 5 | "nsurlsession": require('./nsurlsession.js'), 6 | "helpers": require('./helpers.js') 7 | } 8 | -------------------------------------------------------------------------------- /src/targets/swift/info.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | key: 'swift', 5 | title: 'Swift', 6 | extname: '.swift', 7 | default: 'nsurlsession' 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/cli.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "run": "node %s", 4 | "target":"node", 5 | "clients": [ 6 | "native" 7 | ] 8 | }, 9 | 10 | { 11 | "run": "php %s", 12 | "target": "php", 13 | "clients": [ 14 | "curl" 15 | ] 16 | }, 17 | 18 | { 19 | "run": "python3 %s", 20 | "target": "python", 21 | "clients": [ 22 | "python3" 23 | ] 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /test/fixtures/curl/http1.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "http://mockbin.com/request", 4 | "httpVersion": "HTTP/1.0" 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/curl/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('require-directory')(module); 4 | -------------------------------------------------------------------------------- /test/fixtures/files/hello.txt: -------------------------------------------------------------------------------- 1 | Hello World 2 | -------------------------------------------------------------------------------- /test/fixtures/har.json: -------------------------------------------------------------------------------- 1 | { 2 | "log": { 3 | "version": "1.2", 4 | "creator": { 5 | "name": "HTTPSnippet", 6 | "version": "1.0.0" 7 | }, 8 | "entries": [ 9 | { 10 | "request": { 11 | "method": "GET", 12 | "url": "http://mockbin.com/har" 13 | } 14 | }, 15 | { 16 | "request": { 17 | "method": "POST", 18 | "url": "http://mockbin.com/har" 19 | } 20 | } 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module, {exclude: /output/}) 4 | -------------------------------------------------------------------------------- /test/fixtures/mimetypes.json: -------------------------------------------------------------------------------- 1 | { 2 | "multipart/mixed": { 3 | "method": "POST", 4 | "url": "http://mockbin.com/har", 5 | "postData": { 6 | "mimeType": "multipart/mixed" 7 | } 8 | }, 9 | 10 | "multipart/related": { 11 | "method": "POST", 12 | "url": "http://mockbin.com/har", 13 | "postData": { 14 | "mimeType": "multipart/related" 15 | } 16 | }, 17 | 18 | "multipart/form-data": { 19 | "method": "POST", 20 | "url": "http://mockbin.com/har", 21 | "postData": { 22 | "mimeType": "multipart/form-data" 23 | } 24 | }, 25 | 26 | "multipart/alternative": { 27 | "method": "POST", 28 | "url": "http://mockbin.com/har", 29 | "postData": { 30 | "mimeType": "multipart/alternative" 31 | } 32 | }, 33 | 34 | "application/x-www-form-urlencoded": { 35 | "method": "POST", 36 | "url": "http://mockbin.com/har", 37 | "postData": { 38 | "mimeType": "application/x-www-form-urlencoded" 39 | } 40 | }, 41 | 42 | "text/json": { 43 | "method": "POST", 44 | "url": "http://mockbin.com/har", 45 | "postData": { 46 | "mimeType": "text/json" 47 | } 48 | }, 49 | 50 | "text/x-json": { 51 | "method": "POST", 52 | "url": "http://mockbin.com/har", 53 | "postData": { 54 | "mimeType": "text/x-json" 55 | } 56 | }, 57 | 58 | "application/x-json": { 59 | "method": "POST", 60 | "url": "http://mockbin.com/har", 61 | "postData": { 62 | "mimeType": "application/x-json" 63 | } 64 | }, 65 | 66 | "invalid-json": { 67 | "method": "POST", 68 | "url": "http://mockbin.com/har", 69 | "postData": { 70 | "mimeType": "application/json", 71 | "text": "foo/bar" 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/application-form-encoded.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 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); 13 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/application-json.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | struct curl_slist *headers = NULL; 7 | headers = curl_slist_append(headers, "content-type: application/json"); 8 | curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); 9 | 10 | curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"); 11 | 12 | CURLcode ret = curl_easy_perform(hnd); 13 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/cookies.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | curl_easy_setopt(hnd, CURLOPT_COOKIE, "foo=bar; bar=baz"); 7 | 8 | CURLcode ret = curl_easy_perform(hnd); 9 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/custom-method.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "PROPFIND"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | CURLcode ret = curl_easy_perform(hnd); 7 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/full.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"); 5 | 6 | struct curl_slist *headers = NULL; 7 | headers = curl_slist_append(headers, "content-type: application/x-www-form-urlencoded"); 8 | headers = curl_slist_append(headers, "accept: application/json"); 9 | curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); 10 | 11 | curl_easy_setopt(hnd, CURLOPT_COOKIE, "foo=bar; bar=baz"); 12 | 13 | curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "foo=bar"); 14 | 15 | CURLcode ret = curl_easy_perform(hnd); 16 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/headers.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | struct curl_slist *headers = NULL; 7 | headers = curl_slist_append(headers, "x-foo: Bar"); 8 | headers = curl_slist_append(headers, "accept: application/json"); 9 | curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); 10 | 11 | CURLcode ret = curl_easy_perform(hnd); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/https.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "https://mockbin.com/har"); 5 | 6 | CURLcode ret = curl_easy_perform(hnd); 7 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/multipart-data.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | struct curl_slist *headers = NULL; 7 | headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=---011000010111000001101001"); 8 | curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); 9 | 10 | curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--"); 11 | 12 | CURLcode ret = curl_easy_perform(hnd); 13 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/multipart-file.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | struct curl_slist *headers = NULL; 7 | headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=---011000010111000001101001"); 8 | curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); 9 | 10 | curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--"); 11 | 12 | CURLcode ret = curl_easy_perform(hnd); 13 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/multipart-form-data.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | struct curl_slist *headers = NULL; 7 | headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=---011000010111000001101001"); 8 | curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); 9 | 10 | curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--"); 11 | 12 | CURLcode ret = curl_easy_perform(hnd); 13 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/query.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"); 5 | 6 | CURLcode ret = curl_easy_perform(hnd); 7 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/short.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | CURLcode ret = curl_easy_perform(hnd); 7 | -------------------------------------------------------------------------------- /test/fixtures/output/c/libcurl/text-plain.c: -------------------------------------------------------------------------------- 1 | CURL *hnd = curl_easy_init(); 2 | 3 | curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); 4 | curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har"); 5 | 6 | struct curl_slist *headers = NULL; 7 | headers = curl_slist_append(headers, "content-type: text/plain"); 8 | curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); 9 | 10 | curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "Hello World"); 11 | 12 | CURLcode ret = curl_easy_perform(hnd); 13 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/application-form-encoded.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.POST); 3 | request.AddHeader("content-type", "application/x-www-form-urlencoded"); 4 | request.AddParameter("application/x-www-form-urlencoded", "foo=bar&hello=world", ParameterType.RequestBody); 5 | IRestResponse response = client.Execute(request); 6 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/application-json.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.POST); 3 | request.AddHeader("content-type", "application/json"); 4 | request.AddParameter("application/json", "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}", ParameterType.RequestBody); 5 | IRestResponse response = client.Execute(request); 6 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/cookies.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.POST); 3 | request.AddCookie("foo", "bar"); 4 | request.AddCookie("bar", "baz"); 5 | IRestResponse response = client.Execute(request); 6 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/custom-method.cs: -------------------------------------------------------------------------------- 1 | Method not supported 2 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/full.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"); 2 | var request = new RestRequest(Method.POST); 3 | request.AddHeader("content-type", "application/x-www-form-urlencoded"); 4 | request.AddHeader("accept", "application/json"); 5 | request.AddCookie("foo", "bar"); 6 | request.AddCookie("bar", "baz"); 7 | request.AddParameter("application/x-www-form-urlencoded", "foo=bar", ParameterType.RequestBody); 8 | IRestResponse response = client.Execute(request); 9 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/headers.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.GET); 3 | request.AddHeader("x-foo", "Bar"); 4 | request.AddHeader("accept", "application/json"); 5 | IRestResponse response = client.Execute(request); 6 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/https.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("https://mockbin.com/har"); 2 | var request = new RestRequest(Method.GET); 3 | IRestResponse response = client.Execute(request); 4 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/multipart-data.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.POST); 3 | request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); 4 | request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--", ParameterType.RequestBody); 5 | IRestResponse response = client.Execute(request); 6 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/multipart-file.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.POST); 3 | request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); 4 | request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--", ParameterType.RequestBody); 5 | IRestResponse response = client.Execute(request); 6 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/multipart-form-data.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.POST); 3 | request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); 4 | request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--", ParameterType.RequestBody); 5 | IRestResponse response = client.Execute(request); 6 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/query.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"); 2 | var request = new RestRequest(Method.GET); 3 | IRestResponse response = client.Execute(request); 4 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/short.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.GET); 3 | IRestResponse response = client.Execute(request); 4 | -------------------------------------------------------------------------------- /test/fixtures/output/csharp/restsharp/text-plain.cs: -------------------------------------------------------------------------------- 1 | var client = new RestClient("http://mockbin.com/har"); 2 | var request = new RestRequest(Method.POST); 3 | request.AddHeader("content-type", "text/plain"); 4 | request.AddParameter("text/plain", "Hello World", ParameterType.RequestBody); 5 | IRestResponse response = client.Execute(request); 6 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/application-form-encoded.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "net/http" 7 | "io/ioutil" 8 | ) 9 | 10 | func main() { 11 | 12 | url := "http://mockbin.com/har" 13 | 14 | payload := strings.NewReader("foo=bar&hello=world") 15 | 16 | req, _ := http.NewRequest("POST", url, payload) 17 | 18 | req.Header.Add("content-type", "application/x-www-form-urlencoded") 19 | 20 | res, _ := http.DefaultClient.Do(req) 21 | 22 | defer res.Body.Close() 23 | body, _ := ioutil.ReadAll(res.Body) 24 | 25 | fmt.Println(res) 26 | fmt.Println(string(body)) 27 | 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/application-json.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "net/http" 7 | "io/ioutil" 8 | ) 9 | 10 | func main() { 11 | 12 | url := "http://mockbin.com/har" 13 | 14 | payload := strings.NewReader("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}") 15 | 16 | req, _ := http.NewRequest("POST", url, payload) 17 | 18 | req.Header.Add("content-type", "application/json") 19 | 20 | res, _ := http.DefaultClient.Do(req) 21 | 22 | defer res.Body.Close() 23 | body, _ := ioutil.ReadAll(res.Body) 24 | 25 | fmt.Println(res) 26 | fmt.Println(string(body)) 27 | 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/cookies.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "io/ioutil" 7 | ) 8 | 9 | func main() { 10 | 11 | url := "http://mockbin.com/har" 12 | 13 | req, _ := http.NewRequest("POST", url, nil) 14 | 15 | req.Header.Add("cookie", "foo=bar; bar=baz") 16 | 17 | res, _ := http.DefaultClient.Do(req) 18 | 19 | defer res.Body.Close() 20 | body, _ := ioutil.ReadAll(res.Body) 21 | 22 | fmt.Println(res) 23 | fmt.Println(string(body)) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/custom-method.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "io/ioutil" 7 | ) 8 | 9 | func main() { 10 | 11 | url := "http://mockbin.com/har" 12 | 13 | req, _ := http.NewRequest("PROPFIND", url, nil) 14 | 15 | res, _ := http.DefaultClient.Do(req) 16 | 17 | defer res.Body.Close() 18 | body, _ := ioutil.ReadAll(res.Body) 19 | 20 | fmt.Println(res) 21 | fmt.Println(string(body)) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/full.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "net/http" 7 | "io/ioutil" 8 | ) 9 | 10 | func main() { 11 | 12 | url := "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value" 13 | 14 | payload := strings.NewReader("foo=bar") 15 | 16 | req, _ := http.NewRequest("POST", url, payload) 17 | 18 | req.Header.Add("cookie", "foo=bar; bar=baz") 19 | req.Header.Add("accept", "application/json") 20 | req.Header.Add("content-type", "application/x-www-form-urlencoded") 21 | 22 | res, _ := http.DefaultClient.Do(req) 23 | 24 | defer res.Body.Close() 25 | body, _ := ioutil.ReadAll(res.Body) 26 | 27 | fmt.Println(res) 28 | fmt.Println(string(body)) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/headers.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "io/ioutil" 7 | ) 8 | 9 | func main() { 10 | 11 | url := "http://mockbin.com/har" 12 | 13 | req, _ := http.NewRequest("GET", url, nil) 14 | 15 | req.Header.Add("accept", "application/json") 16 | req.Header.Add("x-foo", "Bar") 17 | 18 | res, _ := http.DefaultClient.Do(req) 19 | 20 | defer res.Body.Close() 21 | body, _ := ioutil.ReadAll(res.Body) 22 | 23 | fmt.Println(res) 24 | fmt.Println(string(body)) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/https.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "io/ioutil" 7 | ) 8 | 9 | func main() { 10 | 11 | url := "https://mockbin.com/har" 12 | 13 | req, _ := http.NewRequest("GET", url, nil) 14 | 15 | res, _ := http.DefaultClient.Do(req) 16 | 17 | defer res.Body.Close() 18 | body, _ := ioutil.ReadAll(res.Body) 19 | 20 | fmt.Println(res) 21 | fmt.Println(string(body)) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/multipart-data.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "net/http" 7 | "io/ioutil" 8 | ) 9 | 10 | func main() { 11 | 12 | url := "http://mockbin.com/har" 13 | 14 | payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--") 15 | 16 | req, _ := http.NewRequest("POST", url, payload) 17 | 18 | req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001") 19 | 20 | res, _ := http.DefaultClient.Do(req) 21 | 22 | defer res.Body.Close() 23 | body, _ := ioutil.ReadAll(res.Body) 24 | 25 | fmt.Println(res) 26 | fmt.Println(string(body)) 27 | 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/multipart-file.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "net/http" 7 | "io/ioutil" 8 | ) 9 | 10 | func main() { 11 | 12 | url := "http://mockbin.com/har" 13 | 14 | payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--") 15 | 16 | req, _ := http.NewRequest("POST", url, payload) 17 | 18 | req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001") 19 | 20 | res, _ := http.DefaultClient.Do(req) 21 | 22 | defer res.Body.Close() 23 | body, _ := ioutil.ReadAll(res.Body) 24 | 25 | fmt.Println(res) 26 | fmt.Println(string(body)) 27 | 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/multipart-form-data.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "net/http" 7 | "io/ioutil" 8 | ) 9 | 10 | func main() { 11 | 12 | url := "http://mockbin.com/har" 13 | 14 | payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--") 15 | 16 | req, _ := http.NewRequest("POST", url, payload) 17 | 18 | req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001") 19 | 20 | res, _ := http.DefaultClient.Do(req) 21 | 22 | defer res.Body.Close() 23 | body, _ := ioutil.ReadAll(res.Body) 24 | 25 | fmt.Println(res) 26 | fmt.Println(string(body)) 27 | 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/query.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "io/ioutil" 7 | ) 8 | 9 | func main() { 10 | 11 | url := "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value" 12 | 13 | req, _ := http.NewRequest("GET", url, nil) 14 | 15 | res, _ := http.DefaultClient.Do(req) 16 | 17 | defer res.Body.Close() 18 | body, _ := ioutil.ReadAll(res.Body) 19 | 20 | fmt.Println(res) 21 | fmt.Println(string(body)) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/short.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "io/ioutil" 7 | ) 8 | 9 | func main() { 10 | 11 | url := "http://mockbin.com/har" 12 | 13 | req, _ := http.NewRequest("GET", url, nil) 14 | 15 | res, _ := http.DefaultClient.Do(req) 16 | 17 | defer res.Body.Close() 18 | body, _ := ioutil.ReadAll(res.Body) 19 | 20 | fmt.Println(res) 21 | fmt.Println(string(body)) 22 | 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/output/go/native/text-plain.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "net/http" 7 | "io/ioutil" 8 | ) 9 | 10 | func main() { 11 | 12 | url := "http://mockbin.com/har" 13 | 14 | payload := strings.NewReader("Hello World") 15 | 16 | req, _ := http.NewRequest("POST", url, payload) 17 | 18 | req.Header.Add("content-type", "text/plain") 19 | 20 | res, _ := http.DefaultClient.Do(req) 21 | 22 | defer res.Body.Close() 23 | body, _ := ioutil.ReadAll(res.Body) 24 | 25 | fmt.Println(res) 26 | fmt.Println(string(body)) 27 | 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/application-form-encoded.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 4 | RequestBody body = RequestBody.create(mediaType, "foo=bar&hello=world"); 5 | Request request = new Request.Builder() 6 | .url("http://mockbin.com/har") 7 | .post(body) 8 | .addHeader("content-type", "application/x-www-form-urlencoded") 9 | .build(); 10 | 11 | Response response = client.newCall(request).execute(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/application-json.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | MediaType mediaType = MediaType.parse("application/json"); 4 | RequestBody body = RequestBody.create(mediaType, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"); 5 | Request request = new Request.Builder() 6 | .url("http://mockbin.com/har") 7 | .post(body) 8 | .addHeader("content-type", "application/json") 9 | .build(); 10 | 11 | Response response = client.newCall(request).execute(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/cookies.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | Request request = new Request.Builder() 4 | .url("http://mockbin.com/har") 5 | .post(null) 6 | .addHeader("cookie", "foo=bar; bar=baz") 7 | .build(); 8 | 9 | Response response = client.newCall(request).execute(); 10 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/custom-method.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | Request request = new Request.Builder() 4 | .url("http://mockbin.com/har") 5 | .method("PROPFIND", null) 6 | .build(); 7 | 8 | Response response = client.newCall(request).execute(); 9 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/full.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); 4 | RequestBody body = RequestBody.create(mediaType, "foo=bar"); 5 | Request request = new Request.Builder() 6 | .url("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") 7 | .post(body) 8 | .addHeader("cookie", "foo=bar; bar=baz") 9 | .addHeader("accept", "application/json") 10 | .addHeader("content-type", "application/x-www-form-urlencoded") 11 | .build(); 12 | 13 | Response response = client.newCall(request).execute(); 14 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/headers.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | Request request = new Request.Builder() 4 | .url("http://mockbin.com/har") 5 | .get() 6 | .addHeader("accept", "application/json") 7 | .addHeader("x-foo", "Bar") 8 | .build(); 9 | 10 | Response response = client.newCall(request).execute(); 11 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/https.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | Request request = new Request.Builder() 4 | .url("https://mockbin.com/har") 5 | .get() 6 | .build(); 7 | 8 | Response response = client.newCall(request).execute(); 9 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/multipart-data.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001"); 4 | RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--"); 5 | Request request = new Request.Builder() 6 | .url("http://mockbin.com/har") 7 | .post(body) 8 | .addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") 9 | .build(); 10 | 11 | Response response = client.newCall(request).execute(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/multipart-file.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001"); 4 | RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--"); 5 | Request request = new Request.Builder() 6 | .url("http://mockbin.com/har") 7 | .post(body) 8 | .addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") 9 | .build(); 10 | 11 | Response response = client.newCall(request).execute(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/multipart-form-data.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001"); 4 | RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--"); 5 | Request request = new Request.Builder() 6 | .url("http://mockbin.com/har") 7 | .post(body) 8 | .addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") 9 | .build(); 10 | 11 | Response response = client.newCall(request).execute(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/query.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | Request request = new Request.Builder() 4 | .url("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") 5 | .get() 6 | .build(); 7 | 8 | Response response = client.newCall(request).execute(); 9 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/short.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | Request request = new Request.Builder() 4 | .url("http://mockbin.com/har") 5 | .get() 6 | .build(); 7 | 8 | Response response = client.newCall(request).execute(); 9 | -------------------------------------------------------------------------------- /test/fixtures/output/java/okhttp/text-plain.java: -------------------------------------------------------------------------------- 1 | OkHttpClient client = new OkHttpClient(); 2 | 3 | MediaType mediaType = MediaType.parse("text/plain"); 4 | RequestBody body = RequestBody.create(mediaType, "Hello World"); 5 | Request request = new Request.Builder() 6 | .url("http://mockbin.com/har") 7 | .post(body) 8 | .addHeader("content-type", "text/plain") 9 | .build(); 10 | 11 | Response response = client.newCall(request).execute(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/application-form-encoded.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.post("http://mockbin.com/har") 2 | .header("content-type", "application/x-www-form-urlencoded") 3 | .body("foo=bar&hello=world") 4 | .asString(); 5 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/application-json.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.post("http://mockbin.com/har") 2 | .header("content-type", "application/json") 3 | .body("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}") 4 | .asString(); 5 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/cookies.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.post("http://mockbin.com/har") 2 | .header("cookie", "foo=bar; bar=baz") 3 | .asString(); 4 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/custom-method.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.customMethod("PROPFIND","http://mockbin.com/har") 2 | .asString(); 3 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/full.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.post("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") 2 | .header("cookie", "foo=bar; bar=baz") 3 | .header("accept", "application/json") 4 | .header("content-type", "application/x-www-form-urlencoded") 5 | .body("foo=bar") 6 | .asString(); 7 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/headers.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.get("http://mockbin.com/har") 2 | .header("accept", "application/json") 3 | .header("x-foo", "Bar") 4 | .asString(); 5 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/https.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.get("https://mockbin.com/har") 2 | .asString(); 3 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/multipart-data.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.post("http://mockbin.com/har") 2 | .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") 3 | .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--") 4 | .asString(); 5 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/multipart-file.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.post("http://mockbin.com/har") 2 | .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") 3 | .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--") 4 | .asString(); 5 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/multipart-form-data.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.post("http://mockbin.com/har") 2 | .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") 3 | .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--") 4 | .asString(); 5 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/query.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.get("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") 2 | .asString(); 3 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/short.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.get("http://mockbin.com/har") 2 | .asString(); 3 | -------------------------------------------------------------------------------- /test/fixtures/output/java/unirest/text-plain.java: -------------------------------------------------------------------------------- 1 | HttpResponse response = Unirest.post("http://mockbin.com/har") 2 | .header("content-type", "text/plain") 3 | .body("Hello World") 4 | .asString(); 5 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/application-form-encoded.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har", 5 | "method": "POST", 6 | "headers": { 7 | "content-type": "application/x-www-form-urlencoded" 8 | }, 9 | "data": { 10 | "foo": "bar", 11 | "hello": "world" 12 | } 13 | } 14 | 15 | $.ajax(settings).done(function (response) { 16 | console.log(response); 17 | }); 18 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/application-json.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har", 5 | "method": "POST", 6 | "headers": { 7 | "content-type": "application/json" 8 | }, 9 | "processData": false, 10 | "data": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" 11 | } 12 | 13 | $.ajax(settings).done(function (response) { 14 | console.log(response); 15 | }); 16 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/cookies.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har", 5 | "method": "POST", 6 | "headers": { 7 | "cookie": "foo=bar; bar=baz" 8 | } 9 | } 10 | 11 | $.ajax(settings).done(function (response) { 12 | console.log(response); 13 | }); 14 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/custom-method.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har", 5 | "method": "PROPFIND", 6 | "headers": {} 7 | } 8 | 9 | $.ajax(settings).done(function (response) { 10 | console.log(response); 11 | }); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/full.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value", 5 | "method": "POST", 6 | "headers": { 7 | "cookie": "foo=bar; bar=baz", 8 | "accept": "application/json", 9 | "content-type": "application/x-www-form-urlencoded" 10 | }, 11 | "data": { 12 | "foo": "bar" 13 | } 14 | } 15 | 16 | $.ajax(settings).done(function (response) { 17 | console.log(response); 18 | }); 19 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/headers.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har", 5 | "method": "GET", 6 | "headers": { 7 | "accept": "application/json", 8 | "x-foo": "Bar" 9 | } 10 | } 11 | 12 | $.ajax(settings).done(function (response) { 13 | console.log(response); 14 | }); 15 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/https.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "https://mockbin.com/har", 5 | "method": "GET", 6 | "headers": {} 7 | } 8 | 9 | $.ajax(settings).done(function (response) { 10 | console.log(response); 11 | }); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/multipart-data.js: -------------------------------------------------------------------------------- 1 | var form = new FormData(); 2 | form.append("foo", "Hello World"); 3 | 4 | var settings = { 5 | "async": true, 6 | "crossDomain": true, 7 | "url": "http://mockbin.com/har", 8 | "method": "POST", 9 | "headers": {}, 10 | "processData": false, 11 | "contentType": false, 12 | "mimeType": "multipart/form-data", 13 | "data": form 14 | } 15 | 16 | $.ajax(settings).done(function (response) { 17 | console.log(response); 18 | }); 19 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/multipart-file.js: -------------------------------------------------------------------------------- 1 | var form = new FormData(); 2 | form.append("foo", "test/fixtures/files/hello.txt"); 3 | 4 | var settings = { 5 | "async": true, 6 | "crossDomain": true, 7 | "url": "http://mockbin.com/har", 8 | "method": "POST", 9 | "headers": {}, 10 | "processData": false, 11 | "contentType": false, 12 | "mimeType": "multipart/form-data", 13 | "data": form 14 | } 15 | 16 | $.ajax(settings).done(function (response) { 17 | console.log(response); 18 | }); 19 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/multipart-form-data.js: -------------------------------------------------------------------------------- 1 | var form = new FormData(); 2 | form.append("foo", "bar"); 3 | 4 | var settings = { 5 | "async": true, 6 | "crossDomain": true, 7 | "url": "http://mockbin.com/har", 8 | "method": "POST", 9 | "headers": {}, 10 | "processData": false, 11 | "contentType": false, 12 | "mimeType": "multipart/form-data", 13 | "data": form 14 | } 15 | 16 | $.ajax(settings).done(function (response) { 17 | console.log(response); 18 | }); 19 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/query.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value", 5 | "method": "GET", 6 | "headers": {} 7 | } 8 | 9 | $.ajax(settings).done(function (response) { 10 | console.log(response); 11 | }); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/short.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har", 5 | "method": "GET", 6 | "headers": {} 7 | } 8 | 9 | $.ajax(settings).done(function (response) { 10 | console.log(response); 11 | }); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/jquery/text-plain.js: -------------------------------------------------------------------------------- 1 | var settings = { 2 | "async": true, 3 | "crossDomain": true, 4 | "url": "http://mockbin.com/har", 5 | "method": "POST", 6 | "headers": { 7 | "content-type": "text/plain" 8 | }, 9 | "data": "Hello World" 10 | } 11 | 12 | $.ajax(settings).done(function (response) { 13 | console.log(response); 14 | }); 15 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/application-form-encoded.js: -------------------------------------------------------------------------------- 1 | var data = "foo=bar&hello=world"; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("POST", "http://mockbin.com/har"); 13 | xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded"); 14 | 15 | xhr.send(data); 16 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/application-json.js: -------------------------------------------------------------------------------- 1 | var data = JSON.stringify({ 2 | "number": 1, 3 | "string": "f\"oo", 4 | "arr": [ 5 | 1, 6 | 2, 7 | 3 8 | ], 9 | "nested": { 10 | "a": "b" 11 | }, 12 | "arr_mix": [ 13 | 1, 14 | "a", 15 | { 16 | "arr_mix_nested": {} 17 | } 18 | ] 19 | }); 20 | 21 | var xhr = new XMLHttpRequest(); 22 | xhr.withCredentials = true; 23 | 24 | xhr.addEventListener("readystatechange", function () { 25 | if (this.readyState === this.DONE) { 26 | console.log(this.responseText); 27 | } 28 | }); 29 | 30 | xhr.open("POST", "http://mockbin.com/har"); 31 | xhr.setRequestHeader("content-type", "application/json"); 32 | 33 | xhr.send(data); 34 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/cookies.js: -------------------------------------------------------------------------------- 1 | var data = null; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("POST", "http://mockbin.com/har"); 13 | xhr.setRequestHeader("cookie", "foo=bar; bar=baz"); 14 | 15 | xhr.send(data); 16 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/custom-method.js: -------------------------------------------------------------------------------- 1 | var data = null; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("PROPFIND", "http://mockbin.com/har"); 13 | 14 | xhr.send(data); 15 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/full.js: -------------------------------------------------------------------------------- 1 | var data = "foo=bar"; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("POST", "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"); 13 | xhr.setRequestHeader("cookie", "foo=bar; bar=baz"); 14 | xhr.setRequestHeader("accept", "application/json"); 15 | xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded"); 16 | 17 | xhr.send(data); 18 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/headers.js: -------------------------------------------------------------------------------- 1 | var data = null; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("GET", "http://mockbin.com/har"); 13 | xhr.setRequestHeader("accept", "application/json"); 14 | xhr.setRequestHeader("x-foo", "Bar"); 15 | 16 | xhr.send(data); 17 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/https.js: -------------------------------------------------------------------------------- 1 | var data = null; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("GET", "https://mockbin.com/har"); 13 | 14 | xhr.send(data); 15 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/multipart-data.js: -------------------------------------------------------------------------------- 1 | var data = new FormData(); 2 | data.append("foo", "Hello World"); 3 | 4 | var xhr = new XMLHttpRequest(); 5 | xhr.withCredentials = true; 6 | 7 | xhr.addEventListener("readystatechange", function () { 8 | if (this.readyState === this.DONE) { 9 | console.log(this.responseText); 10 | } 11 | }); 12 | 13 | xhr.open("POST", "http://mockbin.com/har"); 14 | 15 | xhr.send(data); 16 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/multipart-file.js: -------------------------------------------------------------------------------- 1 | var data = new FormData(); 2 | data.append("foo", "test/fixtures/files/hello.txt"); 3 | 4 | var xhr = new XMLHttpRequest(); 5 | xhr.withCredentials = true; 6 | 7 | xhr.addEventListener("readystatechange", function () { 8 | if (this.readyState === this.DONE) { 9 | console.log(this.responseText); 10 | } 11 | }); 12 | 13 | xhr.open("POST", "http://mockbin.com/har"); 14 | 15 | xhr.send(data); 16 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/multipart-form-data.js: -------------------------------------------------------------------------------- 1 | var data = new FormData(); 2 | data.append("foo", "bar"); 3 | 4 | var xhr = new XMLHttpRequest(); 5 | xhr.withCredentials = true; 6 | 7 | xhr.addEventListener("readystatechange", function () { 8 | if (this.readyState === this.DONE) { 9 | console.log(this.responseText); 10 | } 11 | }); 12 | 13 | xhr.open("POST", "http://mockbin.com/har"); 14 | 15 | xhr.send(data); 16 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/query.js: -------------------------------------------------------------------------------- 1 | var data = null; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("GET", "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"); 13 | 14 | xhr.send(data); 15 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/short.js: -------------------------------------------------------------------------------- 1 | var data = null; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("GET", "http://mockbin.com/har"); 13 | 14 | xhr.send(data); 15 | -------------------------------------------------------------------------------- /test/fixtures/output/javascript/xhr/text-plain.js: -------------------------------------------------------------------------------- 1 | var data = "Hello World"; 2 | 3 | var xhr = new XMLHttpRequest(); 4 | xhr.withCredentials = true; 5 | 6 | xhr.addEventListener("readystatechange", function () { 7 | if (this.readyState === this.DONE) { 8 | console.log(this.responseText); 9 | } 10 | }); 11 | 12 | xhr.open("POST", "http://mockbin.com/har"); 13 | xhr.setRequestHeader("content-type", "text/plain"); 14 | 15 | xhr.send(data); 16 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/application-form-encoded.js: -------------------------------------------------------------------------------- 1 | var qs = require("querystring"); 2 | var http = require("http"); 3 | 4 | var options = { 5 | "method": "POST", 6 | "hostname": "mockbin.com", 7 | "port": null, 8 | "path": "/har", 9 | "headers": { 10 | "content-type": "application/x-www-form-urlencoded" 11 | } 12 | }; 13 | 14 | var req = http.request(options, function (res) { 15 | var chunks = []; 16 | 17 | res.on("data", function (chunk) { 18 | chunks.push(chunk); 19 | }); 20 | 21 | res.on("end", function () { 22 | var body = Buffer.concat(chunks); 23 | console.log(body.toString()); 24 | }); 25 | }); 26 | 27 | req.write(qs.stringify({ foo: 'bar', hello: 'world' })); 28 | req.end(); 29 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/application-json.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "POST", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": { 9 | "content-type": "application/json" 10 | } 11 | }; 12 | 13 | var req = http.request(options, function (res) { 14 | var chunks = []; 15 | 16 | res.on("data", function (chunk) { 17 | chunks.push(chunk); 18 | }); 19 | 20 | res.on("end", function () { 21 | var body = Buffer.concat(chunks); 22 | console.log(body.toString()); 23 | }); 24 | }); 25 | 26 | req.write(JSON.stringify({ number: 1, 27 | string: 'f"oo', 28 | arr: [ 1, 2, 3 ], 29 | nested: { a: 'b' }, 30 | arr_mix: [ 1, 'a', { arr_mix_nested: {} } ] })); 31 | req.end(); 32 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/cookies.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "POST", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": { 9 | "cookie": "foo=bar; bar=baz" 10 | } 11 | }; 12 | 13 | var req = http.request(options, function (res) { 14 | var chunks = []; 15 | 16 | res.on("data", function (chunk) { 17 | chunks.push(chunk); 18 | }); 19 | 20 | res.on("end", function () { 21 | var body = Buffer.concat(chunks); 22 | console.log(body.toString()); 23 | }); 24 | }); 25 | 26 | req.end(); 27 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/custom-method.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "PROPFIND", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": {} 9 | }; 10 | 11 | var req = http.request(options, function (res) { 12 | var chunks = []; 13 | 14 | res.on("data", function (chunk) { 15 | chunks.push(chunk); 16 | }); 17 | 18 | res.on("end", function () { 19 | var body = Buffer.concat(chunks); 20 | console.log(body.toString()); 21 | }); 22 | }); 23 | 24 | req.end(); 25 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/full.js: -------------------------------------------------------------------------------- 1 | var qs = require("querystring"); 2 | var http = require("http"); 3 | 4 | var options = { 5 | "method": "POST", 6 | "hostname": "mockbin.com", 7 | "port": null, 8 | "path": "/har?foo=bar&foo=baz&baz=abc&key=value", 9 | "headers": { 10 | "cookie": "foo=bar; bar=baz", 11 | "accept": "application/json", 12 | "content-type": "application/x-www-form-urlencoded" 13 | } 14 | }; 15 | 16 | var req = http.request(options, function (res) { 17 | var chunks = []; 18 | 19 | res.on("data", function (chunk) { 20 | chunks.push(chunk); 21 | }); 22 | 23 | res.on("end", function () { 24 | var body = Buffer.concat(chunks); 25 | console.log(body.toString()); 26 | }); 27 | }); 28 | 29 | req.write(qs.stringify({ foo: 'bar' })); 30 | req.end(); 31 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/headers.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "GET", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": { 9 | "accept": "application/json", 10 | "x-foo": "Bar" 11 | } 12 | }; 13 | 14 | var req = http.request(options, function (res) { 15 | var chunks = []; 16 | 17 | res.on("data", function (chunk) { 18 | chunks.push(chunk); 19 | }); 20 | 21 | res.on("end", function () { 22 | var body = Buffer.concat(chunks); 23 | console.log(body.toString()); 24 | }); 25 | }); 26 | 27 | req.end(); 28 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/https.js: -------------------------------------------------------------------------------- 1 | var http = require("https"); 2 | 3 | var options = { 4 | "method": "GET", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": {} 9 | }; 10 | 11 | var req = http.request(options, function (res) { 12 | var chunks = []; 13 | 14 | res.on("data", function (chunk) { 15 | chunks.push(chunk); 16 | }); 17 | 18 | res.on("end", function () { 19 | var body = Buffer.concat(chunks); 20 | console.log(body.toString()); 21 | }); 22 | }); 23 | 24 | req.end(); 25 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/multipart-data.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "POST", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": { 9 | "content-type": "multipart/form-data; boundary=---011000010111000001101001" 10 | } 11 | }; 12 | 13 | var req = http.request(options, function (res) { 14 | var chunks = []; 15 | 16 | res.on("data", function (chunk) { 17 | chunks.push(chunk); 18 | }); 19 | 20 | res.on("end", function () { 21 | var body = Buffer.concat(chunks); 22 | console.log(body.toString()); 23 | }); 24 | }); 25 | 26 | req.write("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--"); 27 | req.end(); 28 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/multipart-file.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "POST", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": { 9 | "content-type": "multipart/form-data; boundary=---011000010111000001101001" 10 | } 11 | }; 12 | 13 | var req = http.request(options, function (res) { 14 | var chunks = []; 15 | 16 | res.on("data", function (chunk) { 17 | chunks.push(chunk); 18 | }); 19 | 20 | res.on("end", function () { 21 | var body = Buffer.concat(chunks); 22 | console.log(body.toString()); 23 | }); 24 | }); 25 | 26 | req.write("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--"); 27 | req.end(); 28 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/multipart-form-data.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "POST", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": { 9 | "content-type": "multipart/form-data; boundary=---011000010111000001101001" 10 | } 11 | }; 12 | 13 | var req = http.request(options, function (res) { 14 | var chunks = []; 15 | 16 | res.on("data", function (chunk) { 17 | chunks.push(chunk); 18 | }); 19 | 20 | res.on("end", function () { 21 | var body = Buffer.concat(chunks); 22 | console.log(body.toString()); 23 | }); 24 | }); 25 | 26 | req.write("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--"); 27 | req.end(); 28 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/query.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "GET", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har?foo=bar&foo=baz&baz=abc&key=value", 8 | "headers": {} 9 | }; 10 | 11 | var req = http.request(options, function (res) { 12 | var chunks = []; 13 | 14 | res.on("data", function (chunk) { 15 | chunks.push(chunk); 16 | }); 17 | 18 | res.on("end", function () { 19 | var body = Buffer.concat(chunks); 20 | console.log(body.toString()); 21 | }); 22 | }); 23 | 24 | req.end(); 25 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/short.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "GET", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": {} 9 | }; 10 | 11 | var req = http.request(options, function (res) { 12 | var chunks = []; 13 | 14 | res.on("data", function (chunk) { 15 | chunks.push(chunk); 16 | }); 17 | 18 | res.on("end", function () { 19 | var body = Buffer.concat(chunks); 20 | console.log(body.toString()); 21 | }); 22 | }); 23 | 24 | req.end(); 25 | -------------------------------------------------------------------------------- /test/fixtures/output/node/native/text-plain.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var options = { 4 | "method": "POST", 5 | "hostname": "mockbin.com", 6 | "port": null, 7 | "path": "/har", 8 | "headers": { 9 | "content-type": "text/plain" 10 | } 11 | }; 12 | 13 | var req = http.request(options, function (res) { 14 | var chunks = []; 15 | 16 | res.on("data", function (chunk) { 17 | chunks.push(chunk); 18 | }); 19 | 20 | res.on("end", function () { 21 | var body = Buffer.concat(chunks); 22 | console.log(body.toString()); 23 | }); 24 | }); 25 | 26 | req.write("Hello World"); 27 | req.end(); 28 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/application-form-encoded.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'POST', 4 | url: 'http://mockbin.com/har', 5 | headers: { 'content-type': 'application/x-www-form-urlencoded' }, 6 | form: { foo: 'bar', hello: 'world' } }; 7 | 8 | request(options, function (error, response, body) { 9 | if (error) throw new Error(error); 10 | 11 | console.log(body); 12 | }); 13 | 14 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/application-json.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'POST', 4 | url: 'http://mockbin.com/har', 5 | headers: { 'content-type': 'application/json' }, 6 | body: 7 | { number: 1, 8 | string: 'f"oo', 9 | arr: [ 1, 2, 3 ], 10 | nested: { a: 'b' }, 11 | arr_mix: [ 1, 'a', { arr_mix_nested: {} } ] }, 12 | json: true }; 13 | 14 | request(options, function (error, response, body) { 15 | if (error) throw new Error(error); 16 | 17 | console.log(body); 18 | }); 19 | 20 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/cookies.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var jar = request.jar(); 4 | jar.setCookie(request.cookie("foo=bar"), "http://mockbin.com/har"); 5 | jar.setCookie(request.cookie("bar=baz"), "http://mockbin.com/har"); 6 | 7 | var options = { method: 'POST', url: 'http://mockbin.com/har', jar: 'JAR' }; 8 | 9 | request(options, function (error, response, body) { 10 | if (error) throw new Error(error); 11 | 12 | console.log(body); 13 | }); 14 | 15 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/custom-method.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'PROPFIND', url: 'http://mockbin.com/har' }; 4 | 5 | request(options, function (error, response, body) { 6 | if (error) throw new Error(error); 7 | 8 | console.log(body); 9 | }); 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/full.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var jar = request.jar(); 4 | jar.setCookie(request.cookie("foo=bar"), "http://mockbin.com/har"); 5 | jar.setCookie(request.cookie("bar=baz"), "http://mockbin.com/har"); 6 | 7 | var options = { method: 'POST', 8 | url: 'http://mockbin.com/har', 9 | qs: { foo: [ 'bar', 'baz' ], baz: 'abc', key: 'value' }, 10 | headers: 11 | { 'content-type': 'application/x-www-form-urlencoded', 12 | accept: 'application/json' }, 13 | form: { foo: 'bar' }, 14 | jar: 'JAR' }; 15 | 16 | request(options, function (error, response, body) { 17 | if (error) throw new Error(error); 18 | 19 | console.log(body); 20 | }); 21 | 22 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/headers.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'GET', 4 | url: 'http://mockbin.com/har', 5 | headers: { 'x-foo': 'Bar', accept: 'application/json' } }; 6 | 7 | request(options, function (error, response, body) { 8 | if (error) throw new Error(error); 9 | 10 | console.log(body); 11 | }); 12 | 13 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/https.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'GET', url: 'https://mockbin.com/har' }; 4 | 5 | request(options, function (error, response, body) { 6 | if (error) throw new Error(error); 7 | 8 | console.log(body); 9 | }); 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/multipart-data.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'POST', 4 | url: 'http://mockbin.com/har', 5 | headers: { 'content-type': 'multipart/form-data; boundary=---011000010111000001101001' }, 6 | formData: 7 | { foo: 8 | { value: 'Hello World', 9 | options: { filename: 'hello.txt', contentType: 'text/plain' } } } }; 10 | 11 | request(options, function (error, response, body) { 12 | if (error) throw new Error(error); 13 | 14 | console.log(body); 15 | }); 16 | 17 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/multipart-file.js: -------------------------------------------------------------------------------- 1 | var fs = require("fs"); 2 | var request = require("request"); 3 | 4 | var options = { method: 'POST', 5 | url: 'http://mockbin.com/har', 6 | headers: { 'content-type': 'multipart/form-data; boundary=---011000010111000001101001' }, 7 | formData: 8 | { foo: 9 | { value: 'fs.createReadStream("test/fixtures/files/hello.txt")', 10 | options: 11 | { filename: 'test/fixtures/files/hello.txt', 12 | contentType: 'text/plain' } } } }; 13 | 14 | request(options, function (error, response, body) { 15 | if (error) throw new Error(error); 16 | 17 | console.log(body); 18 | }); 19 | 20 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/multipart-form-data.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'POST', 4 | url: 'http://mockbin.com/har', 5 | headers: { 'content-type': 'multipart/form-data; boundary=---011000010111000001101001' }, 6 | formData: { foo: 'bar' } }; 7 | 8 | request(options, function (error, response, body) { 9 | if (error) throw new Error(error); 10 | 11 | console.log(body); 12 | }); 13 | 14 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/query.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'GET', 4 | url: 'http://mockbin.com/har', 5 | qs: { foo: [ 'bar', 'baz' ], baz: 'abc', key: 'value' } }; 6 | 7 | request(options, function (error, response, body) { 8 | if (error) throw new Error(error); 9 | 10 | console.log(body); 11 | }); 12 | 13 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/short.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'GET', url: 'http://mockbin.com/har' }; 4 | 5 | request(options, function (error, response, body) { 6 | if (error) throw new Error(error); 7 | 8 | console.log(body); 9 | }); 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/output/node/request/text-plain.js: -------------------------------------------------------------------------------- 1 | var request = require("request"); 2 | 3 | var options = { method: 'POST', 4 | url: 'http://mockbin.com/har', 5 | headers: { 'content-type': 'text/plain' }, 6 | body: 'Hello World' }; 7 | 8 | request(options, function (error, response, body) { 9 | if (error) throw new Error(error); 10 | 11 | console.log(body); 12 | }); 13 | 14 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/application-form-encoded.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("POST", "http://mockbin.com/har"); 4 | 5 | req.headers({ 6 | "content-type": "application/x-www-form-urlencoded" 7 | }); 8 | 9 | req.form({ 10 | "foo": "bar", 11 | "hello": "world" 12 | }); 13 | 14 | req.end(function (res) { 15 | if (res.error) throw new Error(res.error); 16 | 17 | console.log(res.body); 18 | }); 19 | 20 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/application-json.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("POST", "http://mockbin.com/har"); 4 | 5 | req.headers({ 6 | "content-type": "application/json" 7 | }); 8 | 9 | req.type("json"); 10 | req.send({ 11 | "number": 1, 12 | "string": "f\"oo", 13 | "arr": [ 14 | 1, 15 | 2, 16 | 3 17 | ], 18 | "nested": { 19 | "a": "b" 20 | }, 21 | "arr_mix": [ 22 | 1, 23 | "a", 24 | { 25 | "arr_mix_nested": {} 26 | } 27 | ] 28 | }); 29 | 30 | req.end(function (res) { 31 | if (res.error) throw new Error(res.error); 32 | 33 | console.log(res.body); 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/cookies.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("POST", "http://mockbin.com/har"); 4 | 5 | var CookieJar = unirest.jar(); 6 | CookieJar.add("foo=bar","http://mockbin.com/har"); 7 | CookieJar.add("bar=baz","http://mockbin.com/har"); 8 | req.jar(CookieJar); 9 | 10 | 11 | req.end(function (res) { 12 | if (res.error) throw new Error(res.error); 13 | 14 | console.log(res.body); 15 | }); 16 | 17 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/custom-method.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("PROPFIND", "http://mockbin.com/har"); 4 | 5 | 6 | req.end(function (res) { 7 | if (res.error) throw new Error(res.error); 8 | 9 | console.log(res.body); 10 | }); 11 | 12 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/full.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("POST", "http://mockbin.com/har"); 4 | 5 | var CookieJar = unirest.jar(); 6 | CookieJar.add("foo=bar","http://mockbin.com/har"); 7 | CookieJar.add("bar=baz","http://mockbin.com/har"); 8 | req.jar(CookieJar); 9 | 10 | req.query({ 11 | "foo": [ 12 | "bar", 13 | "baz" 14 | ], 15 | "baz": "abc", 16 | "key": "value" 17 | }); 18 | 19 | req.headers({ 20 | "content-type": "application/x-www-form-urlencoded", 21 | "accept": "application/json" 22 | }); 23 | 24 | req.form({ 25 | "foo": "bar" 26 | }); 27 | 28 | req.end(function (res) { 29 | if (res.error) throw new Error(res.error); 30 | 31 | console.log(res.body); 32 | }); 33 | 34 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/headers.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("GET", "http://mockbin.com/har"); 4 | 5 | req.headers({ 6 | "x-foo": "Bar", 7 | "accept": "application/json" 8 | }); 9 | 10 | 11 | req.end(function (res) { 12 | if (res.error) throw new Error(res.error); 13 | 14 | console.log(res.body); 15 | }); 16 | 17 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/https.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("GET", "https://mockbin.com/har"); 4 | 5 | 6 | req.end(function (res) { 7 | if (res.error) throw new Error(res.error); 8 | 9 | console.log(res.body); 10 | }); 11 | 12 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/multipart-data.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("POST", "http://mockbin.com/har"); 4 | 5 | req.headers({ 6 | "content-type": "multipart/form-data; boundary=---011000010111000001101001" 7 | }); 8 | 9 | req.multipart([ 10 | { 11 | "body": "Hello World", 12 | "content-type": "text/plain" 13 | } 14 | ]); 15 | 16 | req.end(function (res) { 17 | if (res.error) throw new Error(res.error); 18 | 19 | console.log(res.body); 20 | }); 21 | 22 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/multipart-file.js: -------------------------------------------------------------------------------- 1 | var fs = require("fs"); 2 | var unirest = require("unirest"); 3 | 4 | var req = unirest("POST", "http://mockbin.com/har"); 5 | 6 | req.headers({ 7 | "content-type": "multipart/form-data; boundary=---011000010111000001101001" 8 | }); 9 | 10 | req.multipart([ 11 | { 12 | "body": fs.createReadStream("test/fixtures/files/hello.txt"), 13 | "content-type": "text/plain" 14 | } 15 | ]); 16 | 17 | req.end(function (res) { 18 | if (res.error) throw new Error(res.error); 19 | 20 | console.log(res.body); 21 | }); 22 | 23 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/multipart-form-data.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("POST", "http://mockbin.com/har"); 4 | 5 | req.headers({ 6 | "content-type": "multipart/form-data; boundary=---011000010111000001101001" 7 | }); 8 | 9 | req.multipart([ 10 | { 11 | "body": "bar" 12 | } 13 | ]); 14 | 15 | req.end(function (res) { 16 | if (res.error) throw new Error(res.error); 17 | 18 | console.log(res.body); 19 | }); 20 | 21 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/query.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("GET", "http://mockbin.com/har"); 4 | 5 | req.query({ 6 | "foo": [ 7 | "bar", 8 | "baz" 9 | ], 10 | "baz": "abc", 11 | "key": "value" 12 | }); 13 | 14 | 15 | req.end(function (res) { 16 | if (res.error) throw new Error(res.error); 17 | 18 | console.log(res.body); 19 | }); 20 | 21 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/short.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("GET", "http://mockbin.com/har"); 4 | 5 | 6 | req.end(function (res) { 7 | if (res.error) throw new Error(res.error); 8 | 9 | console.log(res.body); 10 | }); 11 | 12 | -------------------------------------------------------------------------------- /test/fixtures/output/node/unirest/text-plain.js: -------------------------------------------------------------------------------- 1 | var unirest = require("unirest"); 2 | 3 | var req = unirest("POST", "http://mockbin.com/har"); 4 | 5 | req.headers({ 6 | "content-type": "text/plain" 7 | }); 8 | 9 | req.send("Hello World"); 10 | 11 | req.end(function (res) { 12 | if (res.error) throw new Error(res.error); 13 | 14 | console.log(res.body); 15 | }); 16 | 17 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/application-form-encoded.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded" }; 4 | 5 | NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"foo=bar" dataUsingEncoding:NSUTF8StringEncoding]]; 6 | [postData appendData:[@"&hello=world" dataUsingEncoding:NSUTF8StringEncoding]]; 7 | 8 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"] 9 | cachePolicy:NSURLRequestUseProtocolCachePolicy 10 | timeoutInterval:10.0]; 11 | [request setHTTPMethod:@"POST"]; 12 | [request setAllHTTPHeaderFields:headers]; 13 | [request setHTTPBody:postData]; 14 | 15 | NSURLSession *session = [NSURLSession sharedSession]; 16 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 17 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 18 | if (error) { 19 | NSLog(@"%@", error); 20 | } else { 21 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 22 | NSLog(@"%@", httpResponse); 23 | } 24 | }]; 25 | [dataTask resume]; 26 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/application-json.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSDictionary *headers = @{ @"content-type": @"application/json" }; 4 | NSDictionary *parameters = @{ @"number": @1, 5 | @"string": @"f\"oo", 6 | @"arr": @[ @1, @2, @3 ], 7 | @"nested": @{ @"a": @"b" }, 8 | @"arr_mix": @[ @1, @"a", @{ @"arr_mix_nested": @{ } } ] }; 9 | 10 | NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil]; 11 | 12 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"] 13 | cachePolicy:NSURLRequestUseProtocolCachePolicy 14 | timeoutInterval:10.0]; 15 | [request setHTTPMethod:@"POST"]; 16 | [request setAllHTTPHeaderFields:headers]; 17 | [request setHTTPBody:postData]; 18 | 19 | NSURLSession *session = [NSURLSession sharedSession]; 20 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 21 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 22 | if (error) { 23 | NSLog(@"%@", error); 24 | } else { 25 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 26 | NSLog(@"%@", httpResponse); 27 | } 28 | }]; 29 | [dataTask resume]; 30 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/cookies.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSDictionary *headers = @{ @"cookie": @"foo=bar; bar=baz" }; 4 | 5 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"] 6 | cachePolicy:NSURLRequestUseProtocolCachePolicy 7 | timeoutInterval:10.0]; 8 | [request setHTTPMethod:@"POST"]; 9 | [request setAllHTTPHeaderFields:headers]; 10 | 11 | NSURLSession *session = [NSURLSession sharedSession]; 12 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 13 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 14 | if (error) { 15 | NSLog(@"%@", error); 16 | } else { 17 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 18 | NSLog(@"%@", httpResponse); 19 | } 20 | }]; 21 | [dataTask resume]; 22 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/custom-method.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"] 4 | cachePolicy:NSURLRequestUseProtocolCachePolicy 5 | timeoutInterval:10.0]; 6 | [request setHTTPMethod:@"PROPFIND"]; 7 | 8 | NSURLSession *session = [NSURLSession sharedSession]; 9 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 10 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 11 | if (error) { 12 | NSLog(@"%@", error); 13 | } else { 14 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 15 | NSLog(@"%@", httpResponse); 16 | } 17 | }]; 18 | [dataTask resume]; 19 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/full.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSDictionary *headers = @{ @"cookie": @"foo=bar; bar=baz", 4 | @"accept": @"application/json", 5 | @"content-type": @"application/x-www-form-urlencoded" }; 6 | 7 | NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"foo=bar" dataUsingEncoding:NSUTF8StringEncoding]]; 8 | 9 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"] 10 | cachePolicy:NSURLRequestUseProtocolCachePolicy 11 | timeoutInterval:10.0]; 12 | [request setHTTPMethod:@"POST"]; 13 | [request setAllHTTPHeaderFields:headers]; 14 | [request setHTTPBody:postData]; 15 | 16 | NSURLSession *session = [NSURLSession sharedSession]; 17 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 18 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 19 | if (error) { 20 | NSLog(@"%@", error); 21 | } else { 22 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 23 | NSLog(@"%@", httpResponse); 24 | } 25 | }]; 26 | [dataTask resume]; 27 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/headers.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSDictionary *headers = @{ @"accept": @"application/json", 4 | @"x-foo": @"Bar" }; 5 | 6 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"] 7 | cachePolicy:NSURLRequestUseProtocolCachePolicy 8 | timeoutInterval:10.0]; 9 | [request setHTTPMethod:@"GET"]; 10 | [request setAllHTTPHeaderFields:headers]; 11 | 12 | NSURLSession *session = [NSURLSession sharedSession]; 13 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 14 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 15 | if (error) { 16 | NSLog(@"%@", error); 17 | } else { 18 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 19 | NSLog(@"%@", httpResponse); 20 | } 21 | }]; 22 | [dataTask resume]; 23 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/https.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://mockbin.com/har"] 4 | cachePolicy:NSURLRequestUseProtocolCachePolicy 5 | timeoutInterval:10.0]; 6 | [request setHTTPMethod:@"GET"]; 7 | 8 | NSURLSession *session = [NSURLSession sharedSession]; 9 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 10 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 11 | if (error) { 12 | NSLog(@"%@", error); 13 | } else { 14 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 15 | NSLog(@"%@", httpResponse); 16 | } 17 | }]; 18 | [dataTask resume]; 19 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/query.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value"] 4 | cachePolicy:NSURLRequestUseProtocolCachePolicy 5 | timeoutInterval:10.0]; 6 | [request setHTTPMethod:@"GET"]; 7 | 8 | NSURLSession *session = [NSURLSession sharedSession]; 9 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 10 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 11 | if (error) { 12 | NSLog(@"%@", error); 13 | } else { 14 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 15 | NSLog(@"%@", httpResponse); 16 | } 17 | }]; 18 | [dataTask resume]; 19 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/short.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"] 4 | cachePolicy:NSURLRequestUseProtocolCachePolicy 5 | timeoutInterval:10.0]; 6 | [request setHTTPMethod:@"GET"]; 7 | 8 | NSURLSession *session = [NSURLSession sharedSession]; 9 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 10 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 11 | if (error) { 12 | NSLog(@"%@", error); 13 | } else { 14 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 15 | NSLog(@"%@", httpResponse); 16 | } 17 | }]; 18 | [dataTask resume]; 19 | -------------------------------------------------------------------------------- /test/fixtures/output/objc/nsurlsession/text-plain.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NSDictionary *headers = @{ @"content-type": @"text/plain" }; 4 | 5 | NSData *postData = [[NSData alloc] initWithData:[@"Hello World" dataUsingEncoding:NSUTF8StringEncoding]]; 6 | 7 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har"] 8 | cachePolicy:NSURLRequestUseProtocolCachePolicy 9 | timeoutInterval:10.0]; 10 | [request setHTTPMethod:@"POST"]; 11 | [request setAllHTTPHeaderFields:headers]; 12 | [request setHTTPBody:postData]; 13 | 14 | NSURLSession *session = [NSURLSession sharedSession]; 15 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 16 | completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 17 | if (error) { 18 | NSLog(@"%@", error); 19 | } else { 20 | NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 21 | NSLog(@"%@", httpResponse); 22 | } 23 | }]; 24 | [dataTask resume]; 25 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/application-form-encoded.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "content-type" "application/x-www-form-urlencoded" 8 | in 9 | let body = Cohttp_lwt_body.of_string "foo=bar&hello=world" in 10 | 11 | Client.call ~headers ~body `POST uri 12 | >>= fun (res, body_stream) -> 13 | (* Do stuff with the result *) 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/application-json.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "content-type" "application/json" 8 | in 9 | let body = Cohttp_lwt_body.of_string "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" in 10 | 11 | Client.call ~headers ~body `POST uri 12 | >>= fun (res, body_stream) -> 13 | (* Do stuff with the result *) 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/cookies.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "cookie" "foo=bar; bar=baz" 8 | in 9 | 10 | Client.call ~headers `POST uri 11 | >>= fun (res, body_stream) -> 12 | (* Do stuff with the result *) 13 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/custom-method.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | 7 | Client.call (Code.method_of_string "PROPFIND") uri 8 | >>= fun (res, body_stream) -> 9 | (* Do stuff with the result *) 10 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/full.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "cookie" "foo=bar; bar=baz" 8 | |> fun h -> Header.add h "accept" "application/json" 9 | |> fun h -> Header.add h "content-type" "application/x-www-form-urlencoded" 10 | in 11 | let body = Cohttp_lwt_body.of_string "foo=bar" in 12 | 13 | Client.call ~headers ~body `POST uri 14 | >>= fun (res, body_stream) -> 15 | (* Do stuff with the result *) 16 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/headers.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "accept" "application/json" 8 | |> fun h -> Header.add h "x-foo" "Bar" 9 | in 10 | 11 | Client.call ~headers `GET uri 12 | >>= fun (res, body_stream) -> 13 | (* Do stuff with the result *) 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/https.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "https://mockbin.com/har" in 6 | 7 | Client.call `GET uri 8 | >>= fun (res, body_stream) -> 9 | (* Do stuff with the result *) 10 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/multipart-data.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "content-type" "multipart/form-data; boundary=---011000010111000001101001" 8 | in 9 | let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--" in 10 | 11 | Client.call ~headers ~body `POST uri 12 | >>= fun (res, body_stream) -> 13 | (* Do stuff with the result *) 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/multipart-file.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "content-type" "multipart/form-data; boundary=---011000010111000001101001" 8 | in 9 | let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" in 10 | 11 | Client.call ~headers ~body `POST uri 12 | >>= fun (res, body_stream) -> 13 | (* Do stuff with the result *) 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/multipart-form-data.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "content-type" "multipart/form-data; boundary=---011000010111000001101001" 8 | in 9 | let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" in 10 | 11 | Client.call ~headers ~body `POST uri 12 | >>= fun (res, body_stream) -> 13 | (* Do stuff with the result *) 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/query.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value" in 6 | 7 | Client.call `GET uri 8 | >>= fun (res, body_stream) -> 9 | (* Do stuff with the result *) 10 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/short.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | 7 | Client.call `GET uri 8 | >>= fun (res, body_stream) -> 9 | (* Do stuff with the result *) 10 | -------------------------------------------------------------------------------- /test/fixtures/output/ocaml/cohttp/text-plain.ml: -------------------------------------------------------------------------------- 1 | open Cohttp_lwt_unix 2 | open Cohttp 3 | open Lwt 4 | 5 | let uri = Uri.of_string "http://mockbin.com/har" in 6 | let headers = Header.init () 7 | |> fun h -> Header.add h "content-type" "text/plain" 8 | in 9 | let body = Cohttp_lwt_body.of_string "Hello World" in 10 | 11 | Client.call ~headers ~body `POST uri 12 | >>= fun (res, body_stream) -> 13 | (* Do stuff with the result *) 14 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/application-form-encoded.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "POST", 13 | CURLOPT_POSTFIELDS => "foo=bar&hello=world", 14 | CURLOPT_HTTPHEADER => array( 15 | "content-type: application/x-www-form-urlencoded" 16 | ), 17 | )); 18 | 19 | $response = curl_exec($curl); 20 | $err = curl_error($curl); 21 | 22 | curl_close($curl); 23 | 24 | if ($err) { 25 | echo "cURL Error #:" . $err; 26 | } else { 27 | echo $response; 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/application-json.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "POST", 13 | CURLOPT_POSTFIELDS => "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}", 14 | CURLOPT_HTTPHEADER => array( 15 | "content-type: application/json" 16 | ), 17 | )); 18 | 19 | $response = curl_exec($curl); 20 | $err = curl_error($curl); 21 | 22 | curl_close($curl); 23 | 24 | if ($err) { 25 | echo "cURL Error #:" . $err; 26 | } else { 27 | echo $response; 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/cookies.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "POST", 13 | CURLOPT_COOKIE => "foo=bar; bar=baz", 14 | )); 15 | 16 | $response = curl_exec($curl); 17 | $err = curl_error($curl); 18 | 19 | curl_close($curl); 20 | 21 | if ($err) { 22 | echo "cURL Error #:" . $err; 23 | } else { 24 | echo $response; 25 | } 26 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/custom-method.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "PROPFIND", 13 | )); 14 | 15 | $response = curl_exec($curl); 16 | $err = curl_error($curl); 17 | 18 | curl_close($curl); 19 | 20 | if ($err) { 21 | echo "cURL Error #:" . $err; 22 | } else { 23 | echo $response; 24 | } 25 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/full.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "POST", 13 | CURLOPT_POSTFIELDS => "foo=bar", 14 | CURLOPT_COOKIE => "foo=bar; bar=baz", 15 | CURLOPT_HTTPHEADER => array( 16 | "accept: application/json", 17 | "content-type: application/x-www-form-urlencoded" 18 | ), 19 | )); 20 | 21 | $response = curl_exec($curl); 22 | $err = curl_error($curl); 23 | 24 | curl_close($curl); 25 | 26 | if ($err) { 27 | echo "cURL Error #:" . $err; 28 | } else { 29 | echo $response; 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/headers.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "GET", 13 | CURLOPT_HTTPHEADER => array( 14 | "accept: application/json", 15 | "x-foo: Bar" 16 | ), 17 | )); 18 | 19 | $response = curl_exec($curl); 20 | $err = curl_error($curl); 21 | 22 | curl_close($curl); 23 | 24 | if ($err) { 25 | echo "cURL Error #:" . $err; 26 | } else { 27 | echo $response; 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/https.php: -------------------------------------------------------------------------------- 1 | "https://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "GET", 13 | )); 14 | 15 | $response = curl_exec($curl); 16 | $err = curl_error($curl); 17 | 18 | curl_close($curl); 19 | 20 | if ($err) { 21 | echo "cURL Error #:" . $err; 22 | } else { 23 | echo $response; 24 | } 25 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/multipart-data.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "POST", 13 | CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--", 14 | CURLOPT_HTTPHEADER => array( 15 | "content-type: multipart/form-data; boundary=---011000010111000001101001" 16 | ), 17 | )); 18 | 19 | $response = curl_exec($curl); 20 | $err = curl_error($curl); 21 | 22 | curl_close($curl); 23 | 24 | if ($err) { 25 | echo "cURL Error #:" . $err; 26 | } else { 27 | echo $response; 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/multipart-file.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "POST", 13 | CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--", 14 | CURLOPT_HTTPHEADER => array( 15 | "content-type: multipart/form-data; boundary=---011000010111000001101001" 16 | ), 17 | )); 18 | 19 | $response = curl_exec($curl); 20 | $err = curl_error($curl); 21 | 22 | curl_close($curl); 23 | 24 | if ($err) { 25 | echo "cURL Error #:" . $err; 26 | } else { 27 | echo $response; 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/multipart-form-data.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "POST", 13 | CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--", 14 | CURLOPT_HTTPHEADER => array( 15 | "content-type: multipart/form-data; boundary=---011000010111000001101001" 16 | ), 17 | )); 18 | 19 | $response = curl_exec($curl); 20 | $err = curl_error($curl); 21 | 22 | curl_close($curl); 23 | 24 | if ($err) { 25 | echo "cURL Error #:" . $err; 26 | } else { 27 | echo $response; 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/query.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "GET", 13 | )); 14 | 15 | $response = curl_exec($curl); 16 | $err = curl_error($curl); 17 | 18 | curl_close($curl); 19 | 20 | if ($err) { 21 | echo "cURL Error #:" . $err; 22 | } else { 23 | echo $response; 24 | } 25 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/short.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "GET", 13 | )); 14 | 15 | $response = curl_exec($curl); 16 | $err = curl_error($curl); 17 | 18 | curl_close($curl); 19 | 20 | if ($err) { 21 | echo "cURL Error #:" . $err; 22 | } else { 23 | echo $response; 24 | } 25 | -------------------------------------------------------------------------------- /test/fixtures/output/php/curl/text-plain.php: -------------------------------------------------------------------------------- 1 | "http://mockbin.com/har", 7 | CURLOPT_RETURNTRANSFER => true, 8 | CURLOPT_ENCODING => "", 9 | CURLOPT_MAXREDIRS => 10, 10 | CURLOPT_TIMEOUT => 30, 11 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 12 | CURLOPT_CUSTOMREQUEST => "POST", 13 | CURLOPT_POSTFIELDS => "Hello World", 14 | CURLOPT_HTTPHEADER => array( 15 | "content-type: text/plain" 16 | ), 17 | )); 18 | 19 | $response = curl_exec($curl); 20 | $err = curl_error($curl); 21 | 22 | curl_close($curl); 23 | 24 | if ($err) { 25 | echo "cURL Error #:" . $err; 26 | } else { 27 | echo $response; 28 | } 29 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/application-form-encoded.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_POST); 6 | 7 | $request->setHeaders(array( 8 | 'content-type' => 'application/x-www-form-urlencoded' 9 | )); 10 | 11 | $request->setContentType('application/x-www-form-urlencoded'); 12 | $request->setPostFields(array( 13 | 'foo' => 'bar', 14 | 'hello' => 'world' 15 | )); 16 | 17 | try { 18 | $response = $request->send(); 19 | 20 | echo $response->getBody(); 21 | } catch (HttpException $ex) { 22 | echo $ex; 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/application-json.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_POST); 6 | 7 | $request->setHeaders(array( 8 | 'content-type' => 'application/json' 9 | )); 10 | 11 | $request->setBody('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}'); 12 | 13 | try { 14 | $response = $request->send(); 15 | 16 | echo $response->getBody(); 17 | } catch (HttpException $ex) { 18 | echo $ex; 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/cookies.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_POST); 6 | 7 | $request->setCookies(array( 8 | 'bar' => 'baz', 9 | 'foo' => 'bar' 10 | )); 11 | 12 | try { 13 | $response = $request->send(); 14 | 15 | echo $response->getBody(); 16 | } catch (HttpException $ex) { 17 | echo $ex; 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/custom-method.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_PROPFIND); 6 | 7 | try { 8 | $response = $request->send(); 9 | 10 | echo $response->getBody(); 11 | } catch (HttpException $ex) { 12 | echo $ex; 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/full.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_POST); 6 | 7 | $request->setQueryData(array( 8 | 'foo' => array( 9 | 'bar', 10 | 'baz' 11 | ), 12 | 'baz' => 'abc', 13 | 'key' => 'value' 14 | )); 15 | 16 | $request->setHeaders(array( 17 | 'content-type' => 'application/x-www-form-urlencoded', 18 | 'accept' => 'application/json' 19 | )); 20 | 21 | $request->setCookies(array( 22 | 'bar' => 'baz', 23 | 'foo' => 'bar' 24 | )); 25 | 26 | $request->setContentType('application/x-www-form-urlencoded'); 27 | $request->setPostFields(array( 28 | 'foo' => 'bar' 29 | )); 30 | 31 | try { 32 | $response = $request->send(); 33 | 34 | echo $response->getBody(); 35 | } catch (HttpException $ex) { 36 | echo $ex; 37 | } 38 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/headers.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_GET); 6 | 7 | $request->setHeaders(array( 8 | 'x-foo' => 'Bar', 9 | 'accept' => 'application/json' 10 | )); 11 | 12 | try { 13 | $response = $request->send(); 14 | 15 | echo $response->getBody(); 16 | } catch (HttpException $ex) { 17 | echo $ex; 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/https.php: -------------------------------------------------------------------------------- 1 | setUrl('https://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_GET); 6 | 7 | try { 8 | $response = $request->send(); 9 | 10 | echo $response->getBody(); 11 | } catch (HttpException $ex) { 12 | echo $ex; 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/multipart-data.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_POST); 6 | 7 | $request->setHeaders(array( 8 | 'content-type' => 'multipart/form-data; boundary=---011000010111000001101001' 9 | )); 10 | 11 | $request->setBody('-----011000010111000001101001 12 | Content-Disposition: form-data; name="foo"; filename="hello.txt" 13 | Content-Type: text/plain 14 | 15 | Hello World 16 | -----011000010111000001101001--'); 17 | 18 | try { 19 | $response = $request->send(); 20 | 21 | echo $response->getBody(); 22 | } catch (HttpException $ex) { 23 | echo $ex; 24 | } 25 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/multipart-file.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_POST); 6 | 7 | $request->setHeaders(array( 8 | 'content-type' => 'multipart/form-data; boundary=---011000010111000001101001' 9 | )); 10 | 11 | $request->setBody('-----011000010111000001101001 12 | Content-Disposition: form-data; name="foo"; filename="hello.txt" 13 | Content-Type: text/plain 14 | 15 | 16 | -----011000010111000001101001--'); 17 | 18 | try { 19 | $response = $request->send(); 20 | 21 | echo $response->getBody(); 22 | } catch (HttpException $ex) { 23 | echo $ex; 24 | } 25 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/multipart-form-data.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_POST); 6 | 7 | $request->setHeaders(array( 8 | 'content-type' => 'multipart/form-data; boundary=---011000010111000001101001' 9 | )); 10 | 11 | $request->setBody('-----011000010111000001101001 12 | Content-Disposition: form-data; name="foo" 13 | 14 | bar 15 | -----011000010111000001101001--'); 16 | 17 | try { 18 | $response = $request->send(); 19 | 20 | echo $response->getBody(); 21 | } catch (HttpException $ex) { 22 | echo $ex; 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/query.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_GET); 6 | 7 | $request->setQueryData(array( 8 | 'foo' => array( 9 | 'bar', 10 | 'baz' 11 | ), 12 | 'baz' => 'abc', 13 | 'key' => 'value' 14 | )); 15 | 16 | try { 17 | $response = $request->send(); 18 | 19 | echo $response->getBody(); 20 | } catch (HttpException $ex) { 21 | echo $ex; 22 | } 23 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/short.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_GET); 6 | 7 | try { 8 | $response = $request->send(); 9 | 10 | echo $response->getBody(); 11 | } catch (HttpException $ex) { 12 | echo $ex; 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http1/text-plain.php: -------------------------------------------------------------------------------- 1 | setUrl('http://mockbin.com/har'); 5 | $request->setMethod(HTTP_METH_POST); 6 | 7 | $request->setHeaders(array( 8 | 'content-type' => 'text/plain' 9 | )); 10 | 11 | $request->setBody('Hello World'); 12 | 13 | try { 14 | $response = $request->send(); 15 | 16 | echo $response->getBody(); 17 | } catch (HttpException $ex) { 18 | echo $ex; 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/application-form-encoded.php: -------------------------------------------------------------------------------- 1 | append(new http\QueryString(array( 8 | 'foo' => 'bar', 9 | 'hello' => 'world' 10 | ))); 11 | 12 | $request->setRequestUrl('http://mockbin.com/har'); 13 | $request->setRequestMethod('POST'); 14 | $request->setBody($body); 15 | 16 | $request->setHeaders(array( 17 | 'content-type' => 'application/x-www-form-urlencoded' 18 | )); 19 | 20 | $client->enqueue($request)->send(); 21 | $response = $client->getResponse(); 22 | 23 | echo $response->getBody(); 24 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/application-json.php: -------------------------------------------------------------------------------- 1 | append('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}'); 8 | 9 | $request->setRequestUrl('http://mockbin.com/har'); 10 | $request->setRequestMethod('POST'); 11 | $request->setBody($body); 12 | 13 | $request->setHeaders(array( 14 | 'content-type' => 'application/json' 15 | )); 16 | 17 | $client->enqueue($request)->send(); 18 | $response = $client->getResponse(); 19 | 20 | echo $response->getBody(); 21 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/cookies.php: -------------------------------------------------------------------------------- 1 | setRequestUrl('http://mockbin.com/har'); 7 | $request->setRequestMethod('POST'); 8 | 9 | $client->setCookies(array( 10 | 'bar' => 'baz', 11 | 'foo' => 'bar' 12 | )); 13 | 14 | $client->enqueue($request)->send(); 15 | $response = $client->getResponse(); 16 | 17 | echo $response->getBody(); 18 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/custom-method.php: -------------------------------------------------------------------------------- 1 | setRequestUrl('http://mockbin.com/har'); 7 | $request->setRequestMethod('PROPFIND'); 8 | $client->enqueue($request)->send(); 9 | $response = $client->getResponse(); 10 | 11 | echo $response->getBody(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/full.php: -------------------------------------------------------------------------------- 1 | append(new http\QueryString(array( 8 | 'foo' => 'bar' 9 | ))); 10 | 11 | $request->setRequestUrl('http://mockbin.com/har'); 12 | $request->setRequestMethod('POST'); 13 | $request->setBody($body); 14 | 15 | $request->setQuery(new http\QueryString(array( 16 | 'foo' => array( 17 | 'bar', 18 | 'baz' 19 | ), 20 | 'baz' => 'abc', 21 | 'key' => 'value' 22 | ))); 23 | 24 | $request->setHeaders(array( 25 | 'content-type' => 'application/x-www-form-urlencoded', 26 | 'accept' => 'application/json' 27 | )); 28 | 29 | 30 | $client->setCookies(array( 31 | 'bar' => 'baz', 32 | 'foo' => 'bar' 33 | )); 34 | 35 | $client->enqueue($request)->send(); 36 | $response = $client->getResponse(); 37 | 38 | echo $response->getBody(); 39 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/headers.php: -------------------------------------------------------------------------------- 1 | setRequestUrl('http://mockbin.com/har'); 7 | $request->setRequestMethod('GET'); 8 | $request->setHeaders(array( 9 | 'x-foo' => 'Bar', 10 | 'accept' => 'application/json' 11 | )); 12 | 13 | $client->enqueue($request)->send(); 14 | $response = $client->getResponse(); 15 | 16 | echo $response->getBody(); 17 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/https.php: -------------------------------------------------------------------------------- 1 | setRequestUrl('https://mockbin.com/har'); 7 | $request->setRequestMethod('GET'); 8 | $client->enqueue($request)->send(); 9 | $response = $client->getResponse(); 10 | 11 | echo $response->getBody(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/multipart-data.php: -------------------------------------------------------------------------------- 1 | addForm(NULL, array( 8 | array( 9 | 'name' => 'foo', 10 | 'type' => 'text/plain', 11 | 'file' => 'hello.txt', 12 | 'data' => 'Hello World' 13 | ) 14 | )); 15 | 16 | $request->setRequestUrl('http://mockbin.com/har'); 17 | $request->setRequestMethod('POST'); 18 | $request->setBody($body); 19 | 20 | $client->enqueue($request)->send(); 21 | $response = $client->getResponse(); 22 | 23 | echo $response->getBody(); 24 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/multipart-file.php: -------------------------------------------------------------------------------- 1 | addForm(NULL, array( 8 | array( 9 | 'name' => 'foo', 10 | 'type' => 'text/plain', 11 | 'file' => 'test/fixtures/files/hello.txt', 12 | 'data' => null 13 | ) 14 | )); 15 | 16 | $request->setRequestUrl('http://mockbin.com/har'); 17 | $request->setRequestMethod('POST'); 18 | $request->setBody($body); 19 | 20 | $client->enqueue($request)->send(); 21 | $response = $client->getResponse(); 22 | 23 | echo $response->getBody(); 24 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/multipart-form-data.php: -------------------------------------------------------------------------------- 1 | addForm(array( 8 | 'foo' => 'bar' 9 | ), NULL); 10 | 11 | $request->setRequestUrl('http://mockbin.com/har'); 12 | $request->setRequestMethod('POST'); 13 | $request->setBody($body); 14 | 15 | $client->enqueue($request)->send(); 16 | $response = $client->getResponse(); 17 | 18 | echo $response->getBody(); 19 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/query.php: -------------------------------------------------------------------------------- 1 | setRequestUrl('http://mockbin.com/har'); 7 | $request->setRequestMethod('GET'); 8 | $request->setQuery(new http\QueryString(array( 9 | 'foo' => array( 10 | 'bar', 11 | 'baz' 12 | ), 13 | 'baz' => 'abc', 14 | 'key' => 'value' 15 | ))); 16 | 17 | $client->enqueue($request)->send(); 18 | $response = $client->getResponse(); 19 | 20 | echo $response->getBody(); 21 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/short.php: -------------------------------------------------------------------------------- 1 | setRequestUrl('http://mockbin.com/har'); 7 | $request->setRequestMethod('GET'); 8 | $client->enqueue($request)->send(); 9 | $response = $client->getResponse(); 10 | 11 | echo $response->getBody(); 12 | -------------------------------------------------------------------------------- /test/fixtures/output/php/http2/text-plain.php: -------------------------------------------------------------------------------- 1 | append('Hello World'); 8 | 9 | $request->setRequestUrl('http://mockbin.com/har'); 10 | $request->setRequestMethod('POST'); 11 | $request->setBody($body); 12 | 13 | $request->setHeaders(array( 14 | 'content-type' => 'text/plain' 15 | )); 16 | 17 | $client->enqueue($request)->send(); 18 | $response = $client->getResponse(); 19 | 20 | echo $response->getBody(); 21 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/application-form-encoded.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | payload = "foo=bar&hello=world" 6 | 7 | headers = { 'content-type': "application/x-www-form-urlencoded" } 8 | 9 | conn.request("POST", "/har", payload, headers) 10 | 11 | res = conn.getresponse() 12 | data = res.read() 13 | 14 | print(data.decode("utf-8")) 15 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/application-json.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | payload = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" 6 | 7 | headers = { 'content-type': "application/json" } 8 | 9 | conn.request("POST", "/har", payload, headers) 10 | 11 | res = conn.getresponse() 12 | data = res.read() 13 | 14 | print(data.decode("utf-8")) 15 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/cookies.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | headers = { 'cookie': "foo=bar; bar=baz" } 6 | 7 | conn.request("POST", "/har", headers=headers) 8 | 9 | res = conn.getresponse() 10 | data = res.read() 11 | 12 | print(data.decode("utf-8")) 13 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/custom-method.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | conn.request("PROPFIND", "/har") 6 | 7 | res = conn.getresponse() 8 | data = res.read() 9 | 10 | print(data.decode("utf-8")) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/full.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | payload = "foo=bar" 6 | 7 | headers = { 8 | 'cookie': "foo=bar; bar=baz", 9 | 'accept': "application/json", 10 | 'content-type': "application/x-www-form-urlencoded" 11 | } 12 | 13 | conn.request("POST", "/har?foo=bar&foo=baz&baz=abc&key=value", payload, headers) 14 | 15 | res = conn.getresponse() 16 | data = res.read() 17 | 18 | print(data.decode("utf-8")) 19 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/headers.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | headers = { 6 | 'accept': "application/json", 7 | 'x-foo': "Bar" 8 | } 9 | 10 | conn.request("GET", "/har", headers=headers) 11 | 12 | res = conn.getresponse() 13 | data = res.read() 14 | 15 | print(data.decode("utf-8")) 16 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/https.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPSConnection("mockbin.com") 4 | 5 | conn.request("GET", "/har") 6 | 7 | res = conn.getresponse() 8 | data = res.read() 9 | 10 | print(data.decode("utf-8")) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/multipart-data.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--" 6 | 7 | headers = { 'content-type': "multipart/form-data; boundary=---011000010111000001101001" } 8 | 9 | conn.request("POST", "/har", payload, headers) 10 | 11 | res = conn.getresponse() 12 | data = res.read() 13 | 14 | print(data.decode("utf-8")) 15 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/multipart-file.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" 6 | 7 | headers = { 'content-type': "multipart/form-data; boundary=---011000010111000001101001" } 8 | 9 | conn.request("POST", "/har", payload, headers) 10 | 11 | res = conn.getresponse() 12 | data = res.read() 13 | 14 | print(data.decode("utf-8")) 15 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/multipart-form-data.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" 6 | 7 | headers = { 'content-type': "multipart/form-data; boundary=---011000010111000001101001" } 8 | 9 | conn.request("POST", "/har", payload, headers) 10 | 11 | res = conn.getresponse() 12 | data = res.read() 13 | 14 | print(data.decode("utf-8")) 15 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/query.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | conn.request("GET", "/har?foo=bar&foo=baz&baz=abc&key=value") 6 | 7 | res = conn.getresponse() 8 | data = res.read() 9 | 10 | print(data.decode("utf-8")) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/short.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | conn.request("GET", "/har") 6 | 7 | res = conn.getresponse() 8 | data = res.read() 9 | 10 | print(data.decode("utf-8")) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/python3/text-plain.py: -------------------------------------------------------------------------------- 1 | import http.client 2 | 3 | conn = http.client.HTTPConnection("mockbin.com") 4 | 5 | payload = "Hello World" 6 | 7 | headers = { 'content-type': "text/plain" } 8 | 9 | conn.request("POST", "/har", payload, headers) 10 | 11 | res = conn.getresponse() 12 | data = res.read() 13 | 14 | print(data.decode("utf-8")) 15 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/application-form-encoded.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | payload = "foo=bar&hello=world" 6 | headers = {'content-type': 'application/x-www-form-urlencoded'} 7 | 8 | response = requests.request("POST", url, data=payload, headers=headers) 9 | 10 | print(response.text) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/application-json.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | payload = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" 6 | headers = {'content-type': 'application/json'} 7 | 8 | response = requests.request("POST", url, data=payload, headers=headers) 9 | 10 | print(response.text) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/cookies.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | headers = {'cookie': 'foo=bar; bar=baz'} 6 | 7 | response = requests.request("POST", url, headers=headers) 8 | 9 | print(response.text) 10 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/custom-method.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | response = requests.request("PROPFIND", url) 6 | 7 | print(response.text) 8 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/full.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | querystring = {"foo":["bar","baz"],"baz":"abc","key":"value"} 6 | 7 | payload = "foo=bar" 8 | headers = { 9 | 'cookie': "foo=bar; bar=baz", 10 | 'accept': "application/json", 11 | 'content-type': "application/x-www-form-urlencoded" 12 | } 13 | 14 | response = requests.request("POST", url, data=payload, headers=headers, params=querystring) 15 | 16 | print(response.text) 17 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/headers.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | headers = { 6 | 'accept': "application/json", 7 | 'x-foo': "Bar" 8 | } 9 | 10 | response = requests.request("GET", url, headers=headers) 11 | 12 | print(response.text) 13 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/https.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "https://mockbin.com/har" 4 | 5 | response = requests.request("GET", url) 6 | 7 | print(response.text) 8 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/multipart-data.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--" 6 | headers = {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'} 7 | 8 | response = requests.request("POST", url, data=payload, headers=headers) 9 | 10 | print(response.text) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/multipart-file.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" 6 | headers = {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'} 7 | 8 | response = requests.request("POST", url, data=payload, headers=headers) 9 | 10 | print(response.text) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/multipart-form-data.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" 6 | headers = {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'} 7 | 8 | response = requests.request("POST", url, data=payload, headers=headers) 9 | 10 | print(response.text) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/query.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | querystring = {"foo":["bar","baz"],"baz":"abc","key":"value"} 6 | 7 | response = requests.request("GET", url, params=querystring) 8 | 9 | print(response.text) 10 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/short.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | response = requests.request("GET", url) 6 | 7 | print(response.text) 8 | -------------------------------------------------------------------------------- /test/fixtures/output/python/requests/text-plain.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://mockbin.com/har" 4 | 5 | payload = "Hello World" 6 | headers = {'content-type': 'text/plain'} 7 | 8 | response = requests.request("POST", url, data=payload, headers=headers) 9 | 10 | print(response.text) 11 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/application-form-encoded.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Post.new(url) 9 | request["content-type"] = 'application/x-www-form-urlencoded' 10 | request.body = "foo=bar&hello=world" 11 | 12 | response = http.request(request) 13 | puts response.read_body 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/application-json.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Post.new(url) 9 | request["content-type"] = 'application/json' 10 | request.body = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" 11 | 12 | response = http.request(request) 13 | puts response.read_body 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/cookies.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Post.new(url) 9 | request["cookie"] = 'foo=bar; bar=baz' 10 | 11 | response = http.request(request) 12 | puts response.read_body 13 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/custom-method.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | class Net::HTTP::Propfind < Net::HTTPRequest 5 | METHOD = 'PROPFIND' 6 | REQUEST_HAS_BODY = 'false' 7 | RESPONSE_HAS_BODY = true 8 | end 9 | 10 | url = URI("http://mockbin.com/har") 11 | 12 | http = Net::HTTP.new(url.host, url.port) 13 | 14 | request = Net::HTTP::Propfind.new(url) 15 | 16 | response = http.request(request) 17 | puts response.read_body 18 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/full.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Post.new(url) 9 | request["cookie"] = 'foo=bar; bar=baz' 10 | request["accept"] = 'application/json' 11 | request["content-type"] = 'application/x-www-form-urlencoded' 12 | request.body = "foo=bar" 13 | 14 | response = http.request(request) 15 | puts response.read_body 16 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/headers.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Get.new(url) 9 | request["accept"] = 'application/json' 10 | request["x-foo"] = 'Bar' 11 | 12 | response = http.request(request) 13 | puts response.read_body 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/https.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("https://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | http.use_ssl = true 8 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE 9 | 10 | request = Net::HTTP::Get.new(url) 11 | 12 | response = http.request(request) 13 | puts response.read_body 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/multipart-data.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Post.new(url) 9 | request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001' 10 | request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--" 11 | 12 | response = http.request(request) 13 | puts response.read_body 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/multipart-file.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Post.new(url) 9 | request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001' 10 | request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" 11 | 12 | response = http.request(request) 13 | puts response.read_body 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/multipart-form-data.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Post.new(url) 9 | request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001' 10 | request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" 11 | 12 | response = http.request(request) 13 | puts response.read_body 14 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/query.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Get.new(url) 9 | 10 | response = http.request(request) 11 | puts response.read_body 12 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/short.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Get.new(url) 9 | 10 | response = http.request(request) 11 | puts response.read_body 12 | -------------------------------------------------------------------------------- /test/fixtures/output/ruby/native/text-plain.rb: -------------------------------------------------------------------------------- 1 | require 'uri' 2 | require 'net/http' 3 | 4 | url = URI("http://mockbin.com/har") 5 | 6 | http = Net::HTTP.new(url.host, url.port) 7 | 8 | request = Net::HTTP::Post.new(url) 9 | request["content-type"] = 'text/plain' 10 | request.body = "Hello World" 11 | 12 | response = http.request(request) 13 | puts response.read_body 14 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/application-form-encoded.sh: -------------------------------------------------------------------------------- 1 | curl --request POST \ 2 | --url http://mockbin.com/har \ 3 | --header 'content-type: application/x-www-form-urlencoded' \ 4 | --data 'foo=bar&hello=world' 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/application-json.sh: -------------------------------------------------------------------------------- 1 | curl --request POST \ 2 | --url http://mockbin.com/har \ 3 | --header 'content-type: application/json' \ 4 | --data '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}' 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/cookies.sh: -------------------------------------------------------------------------------- 1 | curl --request POST \ 2 | --url http://mockbin.com/har \ 3 | --cookie 'foo=bar; bar=baz' 4 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/custom-method.sh: -------------------------------------------------------------------------------- 1 | curl --request PROPFIND \ 2 | --url http://mockbin.com/har 3 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/full.sh: -------------------------------------------------------------------------------- 1 | curl --request POST \ 2 | --url 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' \ 3 | --header 'accept: application/json' \ 4 | --header 'content-type: application/x-www-form-urlencoded' \ 5 | --cookie 'foo=bar; bar=baz' \ 6 | --data foo=bar 7 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/headers.sh: -------------------------------------------------------------------------------- 1 | curl --request GET \ 2 | --url http://mockbin.com/har \ 3 | --header 'accept: application/json' \ 4 | --header 'x-foo: Bar' 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/http1.sh: -------------------------------------------------------------------------------- 1 | curl --request GET \ 2 | --url "http://mockbin.com/request" \ 3 | --http1.0 4 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/https.sh: -------------------------------------------------------------------------------- 1 | curl --request GET \ 2 | --url https://mockbin.com/har 3 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/multipart-data.sh: -------------------------------------------------------------------------------- 1 | curl --request POST \ 2 | --url http://mockbin.com/har \ 3 | --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ 4 | --form 'foo=Hello World' 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/multipart-file.sh: -------------------------------------------------------------------------------- 1 | curl --request POST \ 2 | --url http://mockbin.com/har \ 3 | --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ 4 | --form foo=@test/fixtures/files/hello.txt 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/multipart-form-data.sh: -------------------------------------------------------------------------------- 1 | curl --request POST \ 2 | --url http://mockbin.com/har \ 3 | --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ 4 | --form foo=bar 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/query.sh: -------------------------------------------------------------------------------- 1 | curl --request GET \ 2 | --url 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' 3 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/short.sh: -------------------------------------------------------------------------------- 1 | curl --request GET \ 2 | --url http://mockbin.com/har 3 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/curl/text-plain.sh: -------------------------------------------------------------------------------- 1 | curl --request POST \ 2 | --url http://mockbin.com/har \ 3 | --header 'content-type: text/plain' \ 4 | --data 'Hello World' 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/application-form-encoded.sh: -------------------------------------------------------------------------------- 1 | http --form POST http://mockbin.com/har \ 2 | content-type:application/x-www-form-urlencoded \ 3 | foo=bar \ 4 | hello=world 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/application-json.sh: -------------------------------------------------------------------------------- 1 | echo '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}' | \ 2 | http POST http://mockbin.com/har \ 3 | content-type:application/json 4 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/cookies.sh: -------------------------------------------------------------------------------- 1 | http POST http://mockbin.com/har \ 2 | cookie:'foo=bar; bar=baz' 3 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/custom-method.sh: -------------------------------------------------------------------------------- 1 | http PROPFIND http://mockbin.com/har 2 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/full.sh: -------------------------------------------------------------------------------- 1 | http --form POST 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' \ 2 | accept:application/json \ 3 | content-type:application/x-www-form-urlencoded \ 4 | cookie:'foo=bar; bar=baz' \ 5 | foo=bar 6 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/headers.sh: -------------------------------------------------------------------------------- 1 | http GET http://mockbin.com/har \ 2 | accept:application/json \ 3 | x-foo:Bar 4 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/https.sh: -------------------------------------------------------------------------------- 1 | http GET https://mockbin.com/har 2 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/multipart-data.sh: -------------------------------------------------------------------------------- 1 | echo '-----011000010111000001101001 2 | Content-Disposition: form-data; name="foo"; filename="hello.txt" 3 | Content-Type: text/plain 4 | 5 | Hello World 6 | -----011000010111000001101001--' | \ 7 | http POST http://mockbin.com/har \ 8 | content-type:'multipart/form-data; boundary=---011000010111000001101001' 9 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/multipart-file.sh: -------------------------------------------------------------------------------- 1 | echo '-----011000010111000001101001 2 | Content-Disposition: form-data; name="foo"; filename="hello.txt" 3 | Content-Type: text/plain 4 | 5 | 6 | -----011000010111000001101001--' | \ 7 | http POST http://mockbin.com/har \ 8 | content-type:'multipart/form-data; boundary=---011000010111000001101001' 9 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/multipart-form-data.sh: -------------------------------------------------------------------------------- 1 | echo '-----011000010111000001101001 2 | Content-Disposition: form-data; name="foo" 3 | 4 | bar 5 | -----011000010111000001101001--' | \ 6 | http POST http://mockbin.com/har \ 7 | content-type:'multipart/form-data; boundary=---011000010111000001101001' 8 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/query.sh: -------------------------------------------------------------------------------- 1 | http GET 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' 2 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/short.sh: -------------------------------------------------------------------------------- 1 | http GET http://mockbin.com/har 2 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/httpie/text-plain.sh: -------------------------------------------------------------------------------- 1 | echo 'Hello World' | \ 2 | http POST http://mockbin.com/har \ 3 | content-type:text/plain 4 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/application-form-encoded.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method POST \ 3 | --header 'content-type: application/x-www-form-urlencoded' \ 4 | --body-data 'foo=bar&hello=world' \ 5 | --output-document \ 6 | - http://mockbin.com/har 7 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/application-json.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method POST \ 3 | --header 'content-type: application/json' \ 4 | --body-data '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}' \ 5 | --output-document \ 6 | - http://mockbin.com/har 7 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/cookies.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method POST \ 3 | --header 'cookie: foo=bar; bar=baz' \ 4 | --output-document \ 5 | - http://mockbin.com/har 6 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/custom-method.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method PROPFIND \ 3 | --output-document \ 4 | - http://mockbin.com/har 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/full.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method POST \ 3 | --header 'cookie: foo=bar; bar=baz' \ 4 | --header 'accept: application/json' \ 5 | --header 'content-type: application/x-www-form-urlencoded' \ 6 | --body-data foo=bar \ 7 | --output-document \ 8 | - 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' 9 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/headers.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method GET \ 3 | --header 'accept: application/json' \ 4 | --header 'x-foo: Bar' \ 5 | --output-document \ 6 | - http://mockbin.com/har 7 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/https.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method GET \ 3 | --output-document \ 4 | - https://mockbin.com/har 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/multipart-data.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method POST \ 3 | --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ 4 | --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--' \ 5 | --output-document \ 6 | - http://mockbin.com/har 7 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/multipart-file.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method POST \ 3 | --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ 4 | --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--' \ 5 | --output-document \ 6 | - http://mockbin.com/har 7 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/multipart-form-data.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method POST \ 3 | --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ 4 | --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"\r\n\r\nbar\r\n-----011000010111000001101001--' \ 5 | --output-document \ 6 | - http://mockbin.com/har 7 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/query.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method GET \ 3 | --output-document \ 4 | - 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/short.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method GET \ 3 | --output-document \ 4 | - http://mockbin.com/har 5 | -------------------------------------------------------------------------------- /test/fixtures/output/shell/wget/text-plain.sh: -------------------------------------------------------------------------------- 1 | wget --quiet \ 2 | --method POST \ 3 | --header 'content-type: text/plain' \ 4 | --body-data 'Hello World' \ 5 | --output-document \ 6 | - http://mockbin.com/har 7 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/application-form-encoded.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = ["content-type": "application/x-www-form-urlencoded"] 4 | 5 | var postData = NSMutableData(data: "foo=bar".dataUsingEncoding(NSUTF8StringEncoding)!) 6 | postData.appendData("&hello=world".dataUsingEncoding(NSUTF8StringEncoding)!) 7 | 8 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 9 | cachePolicy: .UseProtocolCachePolicy, 10 | timeoutInterval: 10.0) 11 | request.HTTPMethod = "POST" 12 | request.allHTTPHeaderFields = headers 13 | request.HTTPBody = postData 14 | 15 | let session = NSURLSession.sharedSession() 16 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 17 | if (error != nil) { 18 | println(error) 19 | } else { 20 | let httpResponse = response as? NSHTTPURLResponse 21 | println(httpResponse) 22 | } 23 | }) 24 | 25 | dataTask.resume() 26 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/application-json.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = ["content-type": "application/json"] 4 | let parameters = [ 5 | "number": 1, 6 | "string": "f\"oo", 7 | "arr": [1, 2, 3], 8 | "nested": ["a": "b"], 9 | "arr_mix": [1, "a", ["arr_mix_nested": []]] 10 | ] 11 | 12 | let postData = NSJSONSerialization.dataWithJSONObject(parameters, options: nil, error: nil) 13 | 14 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 15 | cachePolicy: .UseProtocolCachePolicy, 16 | timeoutInterval: 10.0) 17 | request.HTTPMethod = "POST" 18 | request.allHTTPHeaderFields = headers 19 | request.HTTPBody = postData 20 | 21 | let session = NSURLSession.sharedSession() 22 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 23 | if (error != nil) { 24 | println(error) 25 | } else { 26 | let httpResponse = response as? NSHTTPURLResponse 27 | println(httpResponse) 28 | } 29 | }) 30 | 31 | dataTask.resume() 32 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/cookies.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = ["cookie": "foo=bar; bar=baz"] 4 | 5 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 6 | cachePolicy: .UseProtocolCachePolicy, 7 | timeoutInterval: 10.0) 8 | request.HTTPMethod = "POST" 9 | request.allHTTPHeaderFields = headers 10 | 11 | let session = NSURLSession.sharedSession() 12 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 13 | if (error != nil) { 14 | println(error) 15 | } else { 16 | let httpResponse = response as? NSHTTPURLResponse 17 | println(httpResponse) 18 | } 19 | }) 20 | 21 | dataTask.resume() 22 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/custom-method.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 4 | cachePolicy: .UseProtocolCachePolicy, 5 | timeoutInterval: 10.0) 6 | request.HTTPMethod = "PROPFIND" 7 | 8 | let session = NSURLSession.sharedSession() 9 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 10 | if (error != nil) { 11 | println(error) 12 | } else { 13 | let httpResponse = response as? NSHTTPURLResponse 14 | println(httpResponse) 15 | } 16 | }) 17 | 18 | dataTask.resume() 19 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/full.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = [ 4 | "cookie": "foo=bar; bar=baz", 5 | "accept": "application/json", 6 | "content-type": "application/x-www-form-urlencoded" 7 | ] 8 | 9 | var postData = NSMutableData(data: "foo=bar".dataUsingEncoding(NSUTF8StringEncoding)!) 10 | 11 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")!, 12 | cachePolicy: .UseProtocolCachePolicy, 13 | timeoutInterval: 10.0) 14 | request.HTTPMethod = "POST" 15 | request.allHTTPHeaderFields = headers 16 | request.HTTPBody = postData 17 | 18 | let session = NSURLSession.sharedSession() 19 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 20 | if (error != nil) { 21 | println(error) 22 | } else { 23 | let httpResponse = response as? NSHTTPURLResponse 24 | println(httpResponse) 25 | } 26 | }) 27 | 28 | dataTask.resume() 29 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/headers.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = [ 4 | "accept": "application/json", 5 | "x-foo": "Bar" 6 | ] 7 | 8 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 9 | cachePolicy: .UseProtocolCachePolicy, 10 | timeoutInterval: 10.0) 11 | request.HTTPMethod = "GET" 12 | request.allHTTPHeaderFields = headers 13 | 14 | let session = NSURLSession.sharedSession() 15 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 16 | if (error != nil) { 17 | println(error) 18 | } else { 19 | let httpResponse = response as? NSHTTPURLResponse 20 | println(httpResponse) 21 | } 22 | }) 23 | 24 | dataTask.resume() 25 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/https.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | var request = NSMutableURLRequest(URL: NSURL(string: "https://mockbin.com/har")!, 4 | cachePolicy: .UseProtocolCachePolicy, 5 | timeoutInterval: 10.0) 6 | request.HTTPMethod = "GET" 7 | 8 | let session = NSURLSession.sharedSession() 9 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 10 | if (error != nil) { 11 | println(error) 12 | } else { 13 | let httpResponse = response as? NSHTTPURLResponse 14 | println(httpResponse) 15 | } 16 | }) 17 | 18 | dataTask.resume() 19 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/multipart-data.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = ["content-type": "multipart/form-data; boundary=---011000010111000001101001"] 4 | let parameters = [ 5 | [ 6 | "name": "foo", 7 | "value": "Hello World", 8 | "fileName": "hello.txt", 9 | "contentType": "text/plain" 10 | ] 11 | ] 12 | 13 | let boundary = "---011000010111000001101001" 14 | 15 | var body = "" 16 | var error: NSError? = nil 17 | for param in parameters { 18 | let paramName = param["name"]! 19 | body += "--\(boundary)\r\n" 20 | body += "Content-Disposition:form-data; name=\"\(paramName)\"" 21 | if let filename = param["fileName"] { 22 | let contentType = param["content-type"]! 23 | let fileContent = String(contentsOfFile: filename, encoding: NSUTF8StringEncoding, error: &error) 24 | if (error != nil) { 25 | println(error) 26 | } 27 | body += "; filename=\"\(filename)\"\r\n" 28 | body += "Content-Type: \(contentType)\r\n\r\n" 29 | body += fileContent! 30 | } else if let paramValue = param["value"] { 31 | body += "\r\n\r\n\(paramValue)" 32 | } 33 | } 34 | 35 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 36 | cachePolicy: .UseProtocolCachePolicy, 37 | timeoutInterval: 10.0) 38 | request.HTTPMethod = "POST" 39 | request.allHTTPHeaderFields = headers 40 | request.HTTPBody = postData 41 | 42 | let session = NSURLSession.sharedSession() 43 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 44 | if (error != nil) { 45 | println(error) 46 | } else { 47 | let httpResponse = response as? NSHTTPURLResponse 48 | println(httpResponse) 49 | } 50 | }) 51 | 52 | dataTask.resume() 53 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/multipart-file.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = ["content-type": "multipart/form-data; boundary=---011000010111000001101001"] 4 | let parameters = [ 5 | [ 6 | "name": "foo", 7 | "fileName": "test/fixtures/files/hello.txt", 8 | "contentType": "text/plain" 9 | ] 10 | ] 11 | 12 | let boundary = "---011000010111000001101001" 13 | 14 | var body = "" 15 | var error: NSError? = nil 16 | for param in parameters { 17 | let paramName = param["name"]! 18 | body += "--\(boundary)\r\n" 19 | body += "Content-Disposition:form-data; name=\"\(paramName)\"" 20 | if let filename = param["fileName"] { 21 | let contentType = param["content-type"]! 22 | let fileContent = String(contentsOfFile: filename, encoding: NSUTF8StringEncoding, error: &error) 23 | if (error != nil) { 24 | println(error) 25 | } 26 | body += "; filename=\"\(filename)\"\r\n" 27 | body += "Content-Type: \(contentType)\r\n\r\n" 28 | body += fileContent! 29 | } else if let paramValue = param["value"] { 30 | body += "\r\n\r\n\(paramValue)" 31 | } 32 | } 33 | 34 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 35 | cachePolicy: .UseProtocolCachePolicy, 36 | timeoutInterval: 10.0) 37 | request.HTTPMethod = "POST" 38 | request.allHTTPHeaderFields = headers 39 | request.HTTPBody = postData 40 | 41 | let session = NSURLSession.sharedSession() 42 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 43 | if (error != nil) { 44 | println(error) 45 | } else { 46 | let httpResponse = response as? NSHTTPURLResponse 47 | println(httpResponse) 48 | } 49 | }) 50 | 51 | dataTask.resume() 52 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/multipart-form-data.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = ["content-type": "multipart/form-data; boundary=---011000010111000001101001"] 4 | let parameters = [ 5 | [ 6 | "name": "foo", 7 | "value": "bar" 8 | ] 9 | ] 10 | 11 | let boundary = "---011000010111000001101001" 12 | 13 | var body = "" 14 | var error: NSError? = nil 15 | for param in parameters { 16 | let paramName = param["name"]! 17 | body += "--\(boundary)\r\n" 18 | body += "Content-Disposition:form-data; name=\"\(paramName)\"" 19 | if let filename = param["fileName"] { 20 | let contentType = param["content-type"]! 21 | let fileContent = String(contentsOfFile: filename, encoding: NSUTF8StringEncoding, error: &error) 22 | if (error != nil) { 23 | println(error) 24 | } 25 | body += "; filename=\"\(filename)\"\r\n" 26 | body += "Content-Type: \(contentType)\r\n\r\n" 27 | body += fileContent! 28 | } else if let paramValue = param["value"] { 29 | body += "\r\n\r\n\(paramValue)" 30 | } 31 | } 32 | 33 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 34 | cachePolicy: .UseProtocolCachePolicy, 35 | timeoutInterval: 10.0) 36 | request.HTTPMethod = "POST" 37 | request.allHTTPHeaderFields = headers 38 | request.HTTPBody = postData 39 | 40 | let session = NSURLSession.sharedSession() 41 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 42 | if (error != nil) { 43 | println(error) 44 | } else { 45 | let httpResponse = response as? NSHTTPURLResponse 46 | println(httpResponse) 47 | } 48 | }) 49 | 50 | dataTask.resume() 51 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/query.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")!, 4 | cachePolicy: .UseProtocolCachePolicy, 5 | timeoutInterval: 10.0) 6 | request.HTTPMethod = "GET" 7 | 8 | let session = NSURLSession.sharedSession() 9 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 10 | if (error != nil) { 11 | println(error) 12 | } else { 13 | let httpResponse = response as? NSHTTPURLResponse 14 | println(httpResponse) 15 | } 16 | }) 17 | 18 | dataTask.resume() 19 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/short.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 4 | cachePolicy: .UseProtocolCachePolicy, 5 | timeoutInterval: 10.0) 6 | request.HTTPMethod = "GET" 7 | 8 | let session = NSURLSession.sharedSession() 9 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 10 | if (error != nil) { 11 | println(error) 12 | } else { 13 | let httpResponse = response as? NSHTTPURLResponse 14 | println(httpResponse) 15 | } 16 | }) 17 | 18 | dataTask.resume() 19 | -------------------------------------------------------------------------------- /test/fixtures/output/swift/nsurlsession/text-plain.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | let headers = ["content-type": "text/plain"] 4 | 5 | let postData = NSData(data: "Hello World".dataUsingEncoding(NSUTF8StringEncoding)!) 6 | 7 | var request = NSMutableURLRequest(URL: NSURL(string: "http://mockbin.com/har")!, 8 | cachePolicy: .UseProtocolCachePolicy, 9 | timeoutInterval: 10.0) 10 | request.HTTPMethod = "POST" 11 | request.allHTTPHeaderFields = headers 12 | request.HTTPBody = postData 13 | 14 | let session = NSURLSession.sharedSession() 15 | let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 16 | if (error != nil) { 17 | println(error) 18 | } else { 19 | let httpResponse = response as? NSHTTPURLResponse 20 | println(httpResponse) 21 | } 22 | }) 23 | 24 | dataTask.resume() 25 | -------------------------------------------------------------------------------- /test/fixtures/requests/application-form-encoded.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "POST", 3 | "url": "http://mockbin.com/har", 4 | "headers": [ 5 | { 6 | "name": "content-type", 7 | "value": "application/x-www-form-urlencoded" 8 | } 9 | ], 10 | "postData": { 11 | "mimeType": "application/x-www-form-urlencoded", 12 | "params": [ 13 | { 14 | "name": "foo", 15 | "value": "bar" 16 | }, 17 | { 18 | "name": "hello", 19 | "value": "world" 20 | } 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/requests/application-json.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "POST", 3 | "url": "http://mockbin.com/har", 4 | "headers": [ 5 | { 6 | "name": "content-type", 7 | "value": "application/json" 8 | } 9 | ], 10 | "postData": { 11 | "mimeType": "application/json", 12 | "text": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/requests/cookies.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "POST", 3 | "url": "http://mockbin.com/har", 4 | "cookies": [ 5 | { 6 | "name": "foo", 7 | "value": "bar" 8 | }, 9 | { 10 | "name": "bar", 11 | "value": "baz" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/requests/custom-method.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "PROPFIND", 3 | "url": "http://mockbin.com/har" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/requests/full.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "POST", 3 | "url": "http://mockbin.com/har?key=value", 4 | "httpVersion": "HTTP/1.1", 5 | "queryString": [ 6 | { 7 | "name": "foo", 8 | "value": "bar" 9 | }, 10 | { 11 | "name": "foo", 12 | "value": "baz" 13 | }, 14 | { 15 | "name": "baz", 16 | "value": "abc" 17 | } 18 | ], 19 | "headers": [ 20 | { 21 | "name": "accept", 22 | "value": "application/json" 23 | }, 24 | { 25 | "name": "content-type", 26 | "value": "application/x-www-form-urlencoded" 27 | } 28 | ], 29 | "cookies": [ 30 | { 31 | "name": "foo", 32 | "value": "bar" 33 | }, 34 | { 35 | "name": "bar", 36 | "value": "baz" 37 | } 38 | ], 39 | "postData": { 40 | "mimeType": "application/x-www-form-urlencoded", 41 | "params": [ 42 | { 43 | "name": "foo", 44 | "value": "bar" 45 | } 46 | ] 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/fixtures/requests/headers.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "http://mockbin.com/har", 4 | "headers": [ 5 | { 6 | "name": "accept", 7 | "value": "application/json" 8 | }, 9 | { 10 | "name": "x-foo", 11 | "value": "Bar" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/requests/https.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "https://mockbin.com/har" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/requests/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('require-directory')(module); 4 | -------------------------------------------------------------------------------- /test/fixtures/requests/multipart-data.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "POST", 3 | "url": "http://mockbin.com/har", 4 | "headers": [ 5 | { 6 | "name": "content-type", 7 | "value": "multipart/form-data" 8 | } 9 | ], 10 | "postData": { 11 | "mimeType": "multipart/form-data", 12 | "params": [ 13 | { 14 | "name": "foo", 15 | "value": "Hello World", 16 | "fileName": "hello.txt", 17 | "contentType": "text/plain" 18 | } 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/fixtures/requests/multipart-file.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "POST", 3 | "url": "http://mockbin.com/har", 4 | "headers": [ 5 | { 6 | "name": "content-type", 7 | "value": "multipart/form-data" 8 | } 9 | ], 10 | "postData": { 11 | "mimeType": "multipart/form-data", 12 | "params": [ 13 | { 14 | "name": "foo", 15 | "fileName": "test/fixtures/files/hello.txt", 16 | "contentType": "text/plain" 17 | } 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/fixtures/requests/multipart-form-data.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "POST", 3 | "url": "http://mockbin.com/har", 4 | "headers": [ 5 | { 6 | "name": "content-type", 7 | "value": "multipart/form-data" 8 | } 9 | ], 10 | "postData": { 11 | "mimeType": "multipart/form-data", 12 | "params": [ 13 | { 14 | "name": "foo", 15 | "value": "bar" 16 | } 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/requests/query.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "http://mockbin.com/har?key=value", 4 | "httpVersion": "HTTP/1.1", 5 | "queryString": [ 6 | { 7 | "name": "foo", 8 | "value": "bar" 9 | }, 10 | { 11 | "name": "foo", 12 | "value": "baz" 13 | }, 14 | { 15 | "name": "baz", 16 | "value": "abc" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/requests/short.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "http://mockbin.com/har" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/requests/text-plain.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "POST", 3 | "url": "http://mockbin.com/har", 4 | "headers": [ 5 | { 6 | "name": "content-type", 7 | "value": "text/plain" 8 | } 9 | ], 10 | "postData": { 11 | "mimeType": "text/plain", 12 | "text": "Hello World" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/helpers.js: -------------------------------------------------------------------------------- 1 | /* global describe, it */ 2 | 3 | 'use strict' 4 | 5 | var helpers = require('../src/helpers') 6 | 7 | require('should') 8 | 9 | describe('Reducer', function () { 10 | it('should convert array object pair to key-value object', function (done) { 11 | var query = [ 12 | {name: 'key', value: 'value'}, 13 | {name: 'foo', value: 'bar'} 14 | ] 15 | 16 | var obj = query.reduce(helpers.reducer, {}) 17 | 18 | obj.should.be.an.Object 19 | obj.should.eql({key: 'value', foo: 'bar'}) 20 | 21 | done() 22 | }) 23 | 24 | it('should convert multi-dimensional arrays to key=[array] object', function (done) { 25 | var query = [ 26 | {name: 'key', value: 'value'}, 27 | {name: 'foo', value: 'bar1'}, 28 | {name: 'foo', value: 'bar2'} 29 | ] 30 | 31 | var obj = query.reduce(helpers.reducer, {}) 32 | 33 | obj.should.be.an.Object 34 | obj.should.eql({key: 'value', foo: ['bar1', 'bar2']}) 35 | 36 | done() 37 | }) 38 | }) 39 | -------------------------------------------------------------------------------- /test/tests/c/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/c/libcurl.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('should') 4 | 5 | module.exports = function (snippet, fixtures) {} 6 | -------------------------------------------------------------------------------- /test/tests/csharp/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/csharp/restsharp.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('should') 4 | 5 | module.exports = function (snippet, fixtures) {} 6 | -------------------------------------------------------------------------------- /test/tests/go/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/go/native.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/java/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/java/okhttp.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('should') 4 | 5 | module.exports = function (snippet, fixtures) {} 6 | -------------------------------------------------------------------------------- /test/tests/java/unirest.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('should') 4 | 5 | module.exports = function (snippet, fixtures) {} 6 | -------------------------------------------------------------------------------- /test/tests/javascript/jquery.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/javascript/xhr.js: -------------------------------------------------------------------------------- 1 | /* global it */ 2 | 3 | 'use strict' 4 | 5 | require('should') 6 | 7 | module.exports = function (HTTPSnippet, fixtures) { 8 | it('should not use cors', function () { 9 | var result = new HTTPSnippet(fixtures.requests.short).convert('javascript', 'xhr', { 10 | cors: false 11 | }) 12 | 13 | result.should.be.a.String 14 | result.replace(/\n/g, '').should.eql('var data = null;var xhr = new XMLHttpRequest();xhr.addEventListener("readystatechange", function () { if (this.readyState === this.DONE) { console.log(this.responseText); }});xhr.open("GET", "http://mockbin.com/har");xhr.send(data);') 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /test/tests/node/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/node/native.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/node/request.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/node/unirest.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/objc/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/ocaml/cohttp.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/ocaml/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/php/curl.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/php/http1.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/php/http2.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/php/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/python/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/python/python3.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('should') 4 | 5 | module.exports = function (snippet, fixtures) { 6 | } 7 | -------------------------------------------------------------------------------- /test/tests/python/requests.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('should') 4 | 5 | module.exports = function (snippet, fixtures) { 6 | } 7 | -------------------------------------------------------------------------------- /test/tests/ruby/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/ruby/native.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = function (snippet, fixtures) {} 4 | -------------------------------------------------------------------------------- /test/tests/shell/curl.js: -------------------------------------------------------------------------------- 1 | /* global it */ 2 | 3 | 'use strict' 4 | 5 | require('should') 6 | 7 | module.exports = function (HTTPSnippet, fixtures) { 8 | it('should use short options', function () { 9 | var result = new HTTPSnippet(fixtures.requests.full).convert('shell', 'curl', { 10 | short: true, 11 | indent: false 12 | }) 13 | 14 | result.should.be.a.String 15 | result.should.eql("curl -X POST 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' -H 'accept: application/json' -H 'content-type: application/x-www-form-urlencoded' -b 'foo=bar; bar=baz' -d foo=bar") 16 | }) 17 | 18 | it('should use --http1.0 for HTTP/1.0', function () { 19 | var result = new HTTPSnippet(fixtures.curl.http1).convert('shell', 'curl', { 20 | indent: false 21 | }) 22 | 23 | result.should.be.a.String 24 | result.should.eql('curl --request GET --url http://mockbin.com/request --http1.0') 25 | }) 26 | 27 | it('should use custom indentation', function () { 28 | var result = new HTTPSnippet(fixtures.requests.full).convert('shell', 'curl', { 29 | indent: '@' 30 | }) 31 | 32 | result.should.be.a.String 33 | result.replace(/\\\n/g, '').should.eql("curl --request POST @--url 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' @--header 'accept: application/json' @--header 'content-type: application/x-www-form-urlencoded' @--cookie 'foo=bar; bar=baz' @--data foo=bar") 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /test/tests/shell/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/tests/shell/wget.js: -------------------------------------------------------------------------------- 1 | /* global it */ 2 | 3 | 'use strict' 4 | 5 | require('should') 6 | 7 | module.exports = function (HTTPSnippet, fixtures) { 8 | it('should use short options', function () { 9 | var result = new HTTPSnippet(fixtures.requests.full).convert('shell', 'wget', { 10 | short: true, 11 | indent: false 12 | }) 13 | 14 | result.should.be.a.String 15 | result.should.eql("wget -q --method POST --header 'cookie: foo=bar; bar=baz' --header 'accept: application/json' --header 'content-type: application/x-www-form-urlencoded' --body-data foo=bar -O - 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value'") 16 | }) 17 | 18 | it('should ask for -v output', function () { 19 | var result = new HTTPSnippet(fixtures.requests.short).convert('shell', 'wget', { 20 | short: true, 21 | indent: false, 22 | verbose: true 23 | }) 24 | 25 | result.should.be.a.String 26 | result.should.eql('wget -v --method GET -O - http://mockbin.com/har') 27 | }) 28 | 29 | it('should ask for --verbose output', function () { 30 | var result = new HTTPSnippet(fixtures.requests.short).convert('shell', 'wget', { 31 | short: false, 32 | indent: false, 33 | verbose: true 34 | }) 35 | 36 | result.should.be.a.String 37 | result.should.eql('wget --verbose --method GET --output-document - http://mockbin.com/har') 38 | }) 39 | 40 | it('should use custom indentation', function () { 41 | var result = new HTTPSnippet(fixtures.requests.full).convert('shell', 'wget', { 42 | indent: '@' 43 | }) 44 | 45 | result.should.be.a.String 46 | result.replace(/\\\n/g, '').should.eql("wget --quiet @--method POST @--header 'cookie: foo=bar; bar=baz' @--header 'accept: application/json' @--header 'content-type: application/x-www-form-urlencoded' @--body-data foo=bar @--output-document @- 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value'") 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /test/tests/swift/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | --------------------------------------------------------------------------------