简体   繁体   中英

Keepalive HTTP API call Meteor.JS

I'm working with Meteor and trying to establish NTLM authentication. I'm using the HTTP package to go through the NTLM "handshake" with the remote server. However, I'm running into an issue that I think is caused by the connection not being kept alive. I can't make it all the way through the handshake, because the remote server expects me to reuse the same HTTP connection but I'm making a new one every time (I'm not sure how note to). Below is some of what I'm using to do this. I'd appreciate any help here. Is there any alternative package to HTTP that has a keep alive option? Can I somehow reuse the same connection with the default HTTP package? Thanks.

var msg1 = Ntlm.createMessage1(hostname);
HTTP.get(url, {
    headers: {
        "Authorization": "NTLM " + msg1.toBase64()
    }
}, function (error, result) {
    if (result != null) {
        var response = result.headers["www-authenticate"];
        var msg2 = Ntlm.decodeMessage2(response);

        //here I should respond to msg2 on same kept-alive connection, but I'm not, so it's failing
        var msg3 = Ntlm.createMessage3(msg2, hostname);
        HTTP.get(url, {
            headers: {
                "Authorization": "NTLM " + msg3.toBase64()
            }
        }, function (error, req) {
              if (req != null) {
                    if (req.statusCode == 200) {
                        Ntlm.authorized = true; //success
                    } else {
                        //error, what I'm getting now
                        //"401 - Unauthorized: Access is denied due to invalid credentials"
                    }
              } else Ntlm.error(error);
        });
    } else Ntlm.error(error);
});

I don't think you can keep alive a connection with the default meteor http package. However, there are extensions and replacements to this default package. One of them that seems to support setting keepalive to true is this called http-more . There is more info about this package "requests" support here: https://github.com/request/request#requestoptions-callback

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM