Esempio n. 1
0
    function readArg2(tres, arg2) {
        // TODO: currently does the wrong thing and doesn't implement a
        // multi-map, due to assuming node-like mangling on the other side
        // to ensure singularity
        var arg2res = bufrw.fromBufferResult(HTTPResArg2.RW, arg2);
        if (arg2res.err) {
            callback(arg2res.err, null, null);
        } else if (tres.streamed) {
            callback(null, arg2res.value, tres.arg3);
        } else {
            var body = PassThrough();
            body.end(tres.arg3);
            callback(null, arg2res.value, body);
        }

    }
Esempio n. 2
0
    function onArg2(err, arg2) {
        if (err) {
            sendError(err);
            return;
        }

        var arg2res = bufrw.fromBufferResult(HTTPReqArg2.RW, arg2);
        if (arg2res.err) {
            sendError(arg2res.err);
            return;
        }

        hreq.head = arg2res.value;
        if (req.streamed) {
            hreq.body = req.arg3;
        } else {
            hreq.body = PassThrough();
            hreq.body.end(req.arg3);
        }

        handle();
    }
Esempio n. 3
0
TChannelAsThrift.prototype._parse = function parse(opts) {
    var self = this;
    var spec = opts.spec || self.spec;

    var argsName = opts.endpoint + '_args';
    var argsType = spec.getType(argsName);

    var returnName = opts.endpoint + '_result';
    var resultType = spec.getType(returnName);

    var headRes;
    if (!opts.head) {
        headRes = new Result(null, null);
    } else {
        headRes = bufrw.fromBufferResult(HeaderRW, opts.head);
        if (headRes.err) {
            var headParseErr = errors.ThriftHeadParserError(headRes.err, {
                endpoint: opts.endpoint,
                direction: opts.direction,
                ok: opts.ok,
                headBuf: opts.head.slice(0, 10)
            });

            if (self.logParseFailures) {
                self.logger.warn('Got unexpected invalid thrift arg2', {
                    endpoint: opts.endpoint,
                    direction: opts.direction,
                    ok: opts.ok,
                    headErr: headParseErr
                });
            }

            return new Result(headParseErr);
        }
    }

    var bodyRes;
    var typeName;
    if (opts.direction === 'in.request') {
        bodyRes = argsType.fromBufferResult(opts.body);
    } else if (opts.direction === 'in.response') {
        bodyRes = resultType.fromBufferResult(opts.body);

        if (bodyRes.value && opts.ok) {
            bodyRes.value = bodyRes.value.success;
        } else if (bodyRes.value && !opts.ok) {
            typeName = onlyKey(bodyRes.value);
            bodyRes.value = bodyRes.value[typeName];
        }
    }

    if (bodyRes.err) {
        var bodyParseErr = errors.ThriftBodyParserError(bodyRes.err, {
            endpoint: opts.endpoint,
            direction: opts.direction,
            ok: opts.ok,
            bodyBuf: opts.body.slice(0, 10)
        });

        if (self.logParseFailures) {
            self.logger.warn('Got unexpected invalid thrift for arg3', {
                endpoint: opts.endpoint,
                ok: opts.ok,
                direction: opts.direction,
                bodyErr: bodyParseErr
            });
        }

        return new Result(bodyParseErr);
    }

    return new Result(null, {
        head: headRes.value,
        body: bodyRes.value,
        typeName: typeName
    });
};