Skip to content

Commit

Permalink
fix: lazy-load xmlhttprequest
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 2, 2021
1 parent 5e019c8 commit a31e633
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/ws-kernel-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import isEmpty from "lodash/isEmpty";
import tildify from "tildify";
import { v4 } from "uuid";
import ws from "ws";
import { XMLHttpRequest as NodeXMLHttpRequest } from "xmlhttprequest"; // TODO use @aminya/xmlhttprequest
import { URL } from "url";
import { Kernel, Session, ServerConnection } from "@jupyterlab/services";
import Config from "./config";
Expand Down Expand Up @@ -198,7 +197,9 @@ export default class WSKernelPicker {
options.requestHeaders.Cookie = cookie;

options.xhrFactory = () => {
const request = new NodeXMLHttpRequest();
// we use xmlhttprequest because it allows disabling header protection
const { XMLHttpRequest } = require("xmlhttprequest"); // TODO use @aminya/xmlhttprequest
const request = new XMLHttpRequest();
// Disable protections against setting the Cookie header
request.setDisableHeaderCheck(true);
return request as XMLHttpRequest; // TODO fix the types
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@
"mobx-react": false,
"@nteract/plotly": false,
"refractor": false,
"highlight.js": false
"highlight.js": false,
"xmlhttprequest": false
},
"isLibrary": true
}
Expand Down

0 comments on commit a31e633

Please sign in to comment.