github.com/dbernstein1/tyk@v2.9.0-beta9-dl-apic+incompatible/middleware/testVirtual.js (about) 1 function thisTest(request, session, config) { 2 // Set up a response object 3 var response = { 4 Body: "" 5 Headers: { 6 "test": "virtual-header-1", 7 "test-2": "virtual-header-2", 8 "content-type": "application/json" 9 }, 10 Code: 200 11 } 12 13 // Batch request 14 var batch = { 15 "requests": [ 16 { 17 "method": "GET", 18 "headers": { 19 "x-tyk-test": "1", 20 "x-tyk-version": "1.2", 21 "authorization": "1dbc83b9c431649d7698faa9797e2900f" 22 }, 23 "body": "", 24 "relative_url": "http://httpbin.org/get" 25 }, 26 { 27 "method": "GET", 28 "headers": {}, 29 "body": "", 30 "relative_url": "http://httpbin.org/user-agent" 31 } 32 ], 33 "suppress_parallel_execution": false 34 } 35 36 log("[Virtual Test] Making Upstream Batch Request") 37 var newBody = TykBatchRequest(JSON.stringify(batch)) 38 39 // We know that the requests return JSON in their body, lets flatten it 40 var asJS = JSON.parse(newBody) 41 for (var i in asJS) { 42 asJS[i].body = JSON.parse(asJS[i].body) 43 } 44 45 // We need to send a string object back to Tyk to embed in the response 46 response.Body = JSON.stringify(asJS) 47 48 return TykJsResponse(response, session.meta_data) 49 50 } 51 log("Virtual Test initialised")