{"action":"opened","issue":{"url":"https://api.github.com/repos/jupyter/kernel_gateway_demos/issues/13","repository_url":"https://api.github.com/repos/jupyter/kernel_gateway_demos","labels_url":"https://api.github.com/repos/jupyter/kernel_gateway_demos/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/jupyter/kernel_gateway_demos/issues/13/comments","events_url":"https://api.github.com/repos/jupyter/kernel_gateway_demos/issues/13/events","html_url":"https://github.com/jupyter/kernel_gateway_demos/issues/13","id":149286905,"number":13,"title":"Not able to inject http request headers into client.js","user":{"login":"dockter-84","id":11930758,"avatar_url":"https://avatars.githubusercontent.com/u/11930758?v=3","gravatar_id":"","url":"https://api.github.com/users/dockter-84","html_url":"https://github.com/dockter-84","followers_url":"https://api.github.com/users/dockter-84/followers","following_url":"https://api.github.com/users/dockter-84/following{/other_user}","gists_url":"https://api.github.com/users/dockter-84/gists{/gist_id}","starred_url":"https://api.github.com/users/dockter-84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dockter-84/subscriptions","organizations_url":"https://api.github.com/users/dockter-84/orgs","repos_url":"https://api.github.com/users/dockter-84/repos","events_url":"https://api.github.com/users/dockter-84/events{/privacy}","received_events_url":"https://api.github.com/users/dockter-84/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-18T22:18:00Z","updated_at":"2016-04-18T22:18:00Z","closed_at":null,"body":"This is a continuation of https://github.com/jupyter/jupyter-js-services/issues/132 with the new recommended test client.   Here's the current example of the HTTP request not passing HTTP headers...\r\n\r\nThe following installs the new client code:\r\n```console\r\nrm -rf ~/kernel_gateway_demos\r\ncd ~\r\ngit clone https://github.com/jupyter/kernel_gateway_demos\r\ncd ~/kernel_gateway_demos/node_client_example\r\nnpm install\r\n```\r\nIn `~/kernel_gateway_demos/node_client_example` create client2.js based on https://github.com/jupyter/kernel_gateway_demos/blob/master/node_client_example/client.js  with minor modifications based on the use of the `ajaxSettings` variable.   It looks like this:\r\n```javascript\r\n// Copyright (c) Jupyter Development Team.\r\n// Distributed under the terms of the Modified BSD License.\r\n\r\nvar xmlhttprequest = require('xmlhttprequest');\r\nvar ws = require('ws');\r\nvar fs = require('fs');\r\n\r\nglobal.XMLHttpRequest = xmlhttprequest.XMLHttpRequest;\r\nglobal.WebSocket = ws;\r\n\r\nvar PYTHON_EXAMPLE = fs.readFileSync('example.py', {encoding: 'utf-8'});\r\nvar SCALA_EXAMPLE = fs.readFileSync('example.scala', {encoding: 'utf-8'});\r\n\r\nvar jupyter = require('jupyter-js-services');\r\n\r\nvar kg_host = process.env.GATEWAY_HOST || '192.168.99.100:8888';\r\nvar baseUrl = 'http://' + kg_host;\r\nvar demo_lang = process.env.DEMO_LANG === 'scala' ? 'scala' : 'python';\r\nvar demo_code = (demo_lang === 'scala') ? SCALA_EXAMPLE : PYTHON_EXAMPLE;\r\n\r\nvar ajaxSettings = {\r\n    user: 's334-6c102c3eedad1f-42a9cf195d79',\r\n    password: 'b58e16fa-d9e7-44ed-add0-0bdca872adb7',\r\n    requestHeaders: {\r\n        'X-Spark-service-instance-id': '9b2f515d-5f0d-4f7b-9334-6c102c3eedad'\r\n    }\r\n}\r\n\r\nconsole.log('Targeting server:', kg_host);\r\nconsole.log('Using demo lang:', demo_lang);\r\n\r\n// get info about the available kernels and start a new one\r\njupyter.getKernelSpecs({ baseUrl:  baseUrl}).then((kernelSpecs) => {\r\n    console.log('Available kernelspecs:', kernelSpecs);\r\n    var options = {\r\n        baseUrl: baseUrl,\r\n        name: demo_lang,\r\n        ajaxSettings: ajaxSettings,\t\t\r\n    };\r\n    // request a kernel in the default language (python)\r\n    console.log('Starting kernel:', demo_lang)\r\n    jupyter.startNewKernel(options).then((kernel) => {\r\n        // execute some code\r\n        console.log('Executing sample code');\r\n        var future = kernel.execute({ code: demo_code  } );\r\n        future.onDone = () => {\r\n            // quit when done\r\n            process.exit(0);\r\n        };\r\n        future.onIOPub = (msg) => {\r\n            // print received messages\r\n            console.log('Received message:', msg);\r\n        };\r\n    });\r\n});\r\n```\r\nThen run:\r\n```console\r\nexport GATEWAY_HOST=dev.spark.bluemix.net:8000/jupyter/v1\r\ncd ~/kernel_gateway_demos/node_client_example\r\nDEMO_LANG=python node client2.js\r\n```\r\nFor your test, you may need to change the value of `GATEWAY_HOST` to a webserver where you can inspect the HTTP headers sent.\r\n\r\nThe Nginx log shows that this is what was in the request:\r\n```\r\nGET /jupyter/v1/api/kernelspecs?1461017685992 HTTP/1.1\r\nUser-Agent: node-XMLHttpRequest\r\nAccept: */*\r\nHost: dev.spark.bluemix.net:8000\r\nConnection: close\r\n```\r\nThe HTTP headers were not sent."}}