Skip to content

Commit 1dfd4fb

Browse files
3846masaevilebottnawi
authored andcommitted
fix: add workaround for Origin header in sockjs (#1608)
1 parent bddfe16 commit 1dfd4fb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/Server.js

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ const createCertificate = require('./utils/createCertificate');
4343
const validateOptions = require('schema-utils');
4444
const schema = require('./options.json');
4545

46+
// Workaround for sockjs@~0.3.19
47+
// sockjs will remove Origin header, however Origin header is required for checking host.
48+
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
49+
{
50+
// eslint-disable-next-line global-require
51+
const SockjsSession = require('sockjs/lib/transport').Session;
52+
const decorateConnection = SockjsSession.prototype.decorateConnection;
53+
SockjsSession.prototype.decorateConnection = function(req) {
54+
decorateConnection.call(this, req);
55+
const connection = this.connection;
56+
if (connection.headers && !('origin' in connection.headers) && 'origin' in req.headers) {
57+
connection.headers.origin = req.headers.origin;
58+
}
59+
};
60+
}
61+
4662
// Workaround for node ^8.6.0, ^9.0.0
4763
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
4864
// breaking connection when certificate is not signed with prime256v1

0 commit comments

Comments
 (0)