Azure / azure-relay-node

☁️Node.js library for Azure Relay Hybrid Connections
https://docs.microsoft.com/en-us/azure/service-bus-relay/relay-what-is-it
MIT License
12 stars 15 forks source link

Handling request body in control channel #21

Closed haogang closed 6 years ago

haogang commented 6 years ago

Description

This patch fix a few issues:

This checklist is used to make sure that common guidelines for a pull request are followed.

msftclas commented 6 years ago

CLA assistant check
All CLA requirements met.

clemensv commented 6 years ago

Thanks for the PR. I had the solution already done at that point and was working on the tests. The 1.1.0 package is now published. See here for how this works. One caveat is that the 'message' handler of the underlying 'ws' library buffers up all frames to fin, so large transfers are an issue here. Fixing that will require dropping down one level to explicit frame handling. I'll do that eventually and will remind myself with an issue.

haogang commented 6 years ago

@clemensv Thanks for the fix! Will you please also fix the bug where we don't pass server argument to requestChannelRequest (see https://github.com/Azure/azure-relay-node/blob/master/hyco-https/lib/HybridConnectionHttpsServer.js#L637). The bug will trigger when the client sends a >64KB request.

Simple test case:

const https = require('hyco-https');

const ns = "...";
const path = "...";
const keyrule = "...";
const key = "...";

const token = https.createRelayToken(https.createRelayHttpsUri(ns, path), keyrule, key)
const req = https.request({
    hostname : ns,
    path : (!path || path.length == 0 || path[0] !== '/'?'/':'') + path,
    method : 'POST',
    port : 443,
    headers : {
        'ServiceBusAuthorization' : token,
    }
}, (res) => {
    let error;
    if (res.statusCode !== 200) {
        console.error('Request Failed.\n Status Code:', res.statusCode, res.statusMessage);
        res.resume();
    }
    else {
        res.setEncoding('utf8');
        res.on('data', (chunk) => {
            console.log(`BODY: ${chunk}`);
        });
    };
})

// Sending a > 64KB payload to force rendezvous connection 
req.end('v=' + 'x'.repeat(65 * 1024));