How to use the @creditkarma/thrift-server-core.getProtocol function in @creditkarma/thrift-server-core

To help you get started, we’ve selected a few @creditkarma/thrift-server-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github creditkarma / thrift-server / packages / zipkin-tracing-hapi / src / main / ZipkinTracingHapi.ts View on Github external
(request: Hapi.Request, reply: Hapi.ResponseToolkit) => {
                    const requestMethod: string =
                        isThrift === true
                            ? Core.readThriftMethod(
                                  request.payload as Buffer,
                                  Core.getTransport(transport),
                                  Core.getProtocol(protocol),
                              )
                            : request.method

                    const normalHeaders: Core.IRequestHeaders = normalizeHeaders(
                        request.headers,
                    )

                    return tracer.scoped(() => {
                        const traceId: TraceId = instrumentation.recordRequest(
                            requestMethod,
                            Core.formatUrl(url.format(request.url)),
                            (header: string): option.IOption => {
                                const val = normalHeaders[header.toLowerCase()]
                                if (val !== null && val !== undefined) {
                                    return new option.Some(val)
                                } else {
github creditkarma / thrift-server / packages / thrift-server-express / src / main / ThriftServerExpress.ts View on Github external
return (
        request: ThriftRequest,
        response: express.Response,
        next: express.NextFunction,
    ): void => {
        const Transport: ITransportConstructor = getTransport(
            pluginOptions.transport,
        )
        const Protocol: IProtocolConstructor = getProtocol(
            pluginOptions.protocol,
        )
        const buffer: Buffer = request.body

        const method: string = readThriftMethod(buffer, Transport, Protocol)

        request.thrift = {
            requestMethod: method,
            processor: pluginOptions.handler,
            transport: pluginOptions.transport || 'buffered',
            protocol: pluginOptions.protocol || 'binary',
        }

        try {
            process({
                processor: pluginOptions.handler,
github creditkarma / thrift-server / packages / thrift-client-context-filter / src / main / appendThriftObject.ts View on Github external
export function appendThriftObject(
    value: LooseType,
    data: Buffer,
    ThriftCodec: IStructCodec,
    transportType: TransportType = 'buffered',
    protocolType: ProtocolType = 'binary',
): Promise {
    const Transport: ITransportConstructor = getTransport(transportType)
    const Protocol: IProtocolConstructor = getProtocol(protocolType)

    return encode(value, ThriftCodec, Transport, Protocol).then(
        (encoded: Buffer) => {
            return Buffer.concat([encoded, data])
        },
    )
}
github creditkarma / thrift-server / packages / thrift-client-ttwitter-filter / src / main / ThriftClientTTwitterFilter.ts View on Github external
function upgradeRequest(
    transportType: TransportType = 'buffered',
    protocolType: ProtocolType = 'binary',
): Buffer {
    const Transport: ITransportConstructor = getTransport(transportType)
    const Protocol: IProtocolConstructor = getProtocol(protocolType)
    const options: TTwitter.ConnectionOptions = new TTwitter.ConnectionOptions()
    const writer: TTransport = new Transport()
    const output: TProtocol = new Protocol(writer)

    output.writeMessageBegin(CAN_TRACE_METHOD_NAME, MessageType.CALL, 0)
    options.write(output)
    output.writeMessageEnd()

    return output.flush()
}
github alitelabs / tyx / src / core / thrift.ts View on Github external
constructor(pluginOptions: ICoreThriftHandlerOptions) {
    this.pluginOptions = pluginOptions;
    this.transport = getTransport(pluginOptions.transport);
    this.protocol = getProtocol(pluginOptions.protocol);
  }
github creditkarma / thrift-server / packages / thrift-server-hapi / src / main / ThriftServerHapi.ts View on Github external
export function ThriftServerHapi<
    TProcessor extends Core.IThriftProcessor
>(pluginOptions: IHapiPluginOptions): ThriftHapiPlugin {
    const thriftOptions: IHapiServerOptions =
        pluginOptions.thriftOptions
    const logger: Core.LogFunction = thriftOptions.logger || defaultLogger
    const thriftPath: string = Core.normalizePath(
        pluginOptions.path || DEFAULT_PATH,
    )
    const serviceName: string = pluginOptions.thriftOptions.serviceName

    const Transport: Core.ITransportConstructor = Core.getTransport(
        thriftOptions.transport,
    )
    const Protocol: Core.IProtocolConstructor = Core.getProtocol(
        thriftOptions.protocol,
    )
    const processor: Core.IThriftProcessor = thriftOptions.handler
    const rawServiceName: string = processor._serviceName

    return {
        name: require('../../package.json').name,
        version: require('../../package.json').version,
        multiple: true,
        async register(server: Hapi.Server, nothing: void): Promise {
            if (
                server.plugins.thrift !== undefined &&
                (server.plugins.thrift.transport !==
                    (thriftOptions.transport || 'buffered') ||
                    server.plugins.thrift.protocol !==
                        (thriftOptions.protocol || 'binary'))
github creditkarma / thrift-server / packages / zipkin-tracing-express / src / main / ZipkinTracingExpress.ts View on Github external
tracer.scoped(() => {
            const requestMethod: string =
                isThrift === true
                    ? readThriftMethod(
                          request.body,
                          getTransport(transport),
                          getProtocol(protocol),
                      )
                    : request.method

            const normalHeaders: IRequestHeaders = normalizeHeaders(
                request.headers,
            )

            function readHeader(header: string): option.IOption {
                const val = normalHeaders[header.toLocaleLowerCase()]
                if (val !== null && val !== undefined) {
                    return new option.Some(val)
                } else {
                    return option.None
                }
            }