Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public send(dataToSend: Buffer, context: any = {}): Promise {
const requestMethod: string = readThriftMethod(
dataToSend,
this.Transport,
this.Protocol,
)
const handlers: Array> = this.handlersForMethod(
requestMethod,
)
const thriftRequest: IThriftRequest = {
data: dataToSend,
methodName: requestMethod,
uri: `${this.hostName}:${this.port}`,
context,
}
const applyHandlers = (
currentRequest: IThriftRequest,
(
res: IRequestResponse,
): Promise => {
if (readThriftMethod(res.body) === 'add') {
return Promise.resolve(res)
} else {
return Promise.reject(
new Error(
`Unrecognized method name: ${readThriftMethod(
request.data,
)}`,
),
)
}
},
)
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
handler(
request: IThriftRequest,
next: NextFunction,
): Promise {
if (thrift.readThriftMethod(request.data) === 'fake') {
return next()
} else {
return Promise.reject(
new Error(
`Unrecognized method name: ${thrift.readThriftMethod(
request.data,
)}`,
),
)
}
},
},
handler(
req: IThriftRequest,
next: NextFunction,
): Promise {
if (thrift.readThriftMethod(req.data) === 'add') {
return next()
} else {
return Promise.reject(
new Error(
`Unrecognized method name: ${thrift.readThriftMethod(
req.data,
)}`,
),
)
}
},
})
return next().then((response: IRequestResponse) => {
if (readThriftMethod(response.body) === 'add') {
return Promise.resolve(response)
} else {
return Promise.reject(
new Error(
`Unrecognized method name: ${readThriftMethod(
response.body,
)}`,
),
)
}
})
},
handler(
request: IThriftRequest,
next: NextFunction,
): Promise {
if (thrift.readThriftMethod(request.data) === 'fake') {
return next()
} else {
return Promise.reject(
new Error(
`Unrecognized method name: ${thrift.readThriftMethod(
request.data,
)}`,
),
)
}
},
},
const handler: Hapi.Lifecycle.Method = (
request: Hapi.Request,
reply: Hapi.ResponseToolkit,
) => {
const buffer: Buffer = Core.stripStruct(
request.payload as Buffer,
)
const method: string = Core.readThriftMethod(
buffer,
Transport,
Protocol,
)
request.plugins.thrift = {
requestMethod: method,
}
return Core.process({
processor,
buffer,
Transport,
Protocol,
context: request,
})
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,
buffer,
Transport,
Protocol,
context: request,
}).then(
public send(
dataToSend: Buffer,
context: RequestOptions = {},
): Promise {
const requestMethod: string = Core.readThriftMethod(
dataToSend,
this.Transport,
this.Protocol,
)
const filters: Array<
RequestHandler
> = this.filtersForMethod(requestMethod)
const thriftRequest: IThriftRequest = {
data: dataToSend,
methodName: requestMethod,
uri: this.url,
context,
}