socketio / engine.io-client

The engine used in the Socket.IO JavaScript client, which manages the low-level transports such as HTTP long-polling, WebSocket and WebTransport.

Home Page:https://socket.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ExtraHeaders doesn't work in browser

lu4 opened this issue · comments

You want to:

  • report a bug
  • request a feature

Current behaviour

The feature #519 doesn't work. ExtraHeaders cancelled out through the call to undefined function in xhr called setDisableHeaderCheck.

Steps to reproduce (if the current behaviour is a bug)

Browser code:

let engine = engineio({
    transportOptions: {
        polling: {
            extraHeaders: {
                'X-TEST': 'ZZZ'
            }
        }
    }
});

engine.on('open', () => {
    console.log(['open', engine]);

    engine.send('another test');

    engine.on('message', (data) => {
        console.log(['message', data]);
    });

    engine.on('close', () => {
        console.log(['close', engine]);
    });
});

Server code:

let engineServer = engine.attach(httpsServer);

engineServer.on('connection', function (socket: any) {
    debugger; // socket.request.headers does not contain X-TEST header
    console.log(['connection', socket]);

    socket.send('test');

    socket.on('message', function(data: any) {
        console.log(['message', data, socket]);
    });

    socket.on('close', function() {
        console.log(['close', socket]);
    });
});

Expected behaviour

Headers are transferred from browser to client

Setup

  • OS: Mac OS X Sierra
  • browser: Google Chrome Version 55.0.2883.95 (64-bit)
  • engine.io version: 2.0.0

Other information (e.g. stacktraces, related issues, suggestions how to fix)

The problem seems to be little bit further along the road, to be specific with

xhr.setDisableHeaderCheck(true);

in xhr.setDisableHeaderCheck(true); xhr doesn't contain setDisableHeaderCheck, so what's the reason to accept extraHeaders if they will be cancelled later?