Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@improbable-eng/grpc-web": "^0.11.0",
"compression": "^1.0.3",
"debug": "^4.3.2",
"express": "^4.16.3",
"express": "^4.17.13",
"fast-text-encoding": "^1.0.0",
"isomorphic-fetch": "^2.2.1",
"lodash": "^4.17.5",
Expand All @@ -28,7 +28,7 @@
"@improbable-eng/grpc-web-node-http-transport": "^0.11.0",
"@types/chai": "^4.0.0",
"@types/debug": "^4.1.7",
"@types/express": "^4.11.1",
"@types/express": "^4.17.13",
"@types/fetch-mock": "^7.3.1",
"@types/lodash": "^4.14.106",
"@types/mocha": "^5.2.7",
Expand Down
4 changes: 2 additions & 2 deletions src/client/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as events from 'events';
import { retryStream } from './stream_retrier';
import debug from 'debug';

const debugLog = debug('rpc_ts:client:service')
const debugLog = debug('rpc_ts:client:service');

/**
* Default list of [[ModuleRpcCommon.RpcErrorType]] error types that
Expand Down Expand Up @@ -218,7 +218,7 @@ export class Service<
// the fact that it is a unary method.
const startCall = Date.now();
const { response } = await this.call(method as any, request);
debugLog(`${method} call time ${Date.now() - startCall}ms`)
debugLog(`${method} call time ${Date.now() - startCall}ms`);
return response;
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,5 @@ export enum RpcErrorType {
* The maps are produced and decoded by the client/server context connectors.
*/
export interface EncodedContext {
[key: string]: string;
[key: string]: string | number;
}
2 changes: 1 addition & 1 deletion src/context/client/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class TimestampClientContextConnector
);
}
return {
date,
date: date.toString(),
};
}
}
4 changes: 2 additions & 2 deletions src/context/server/token_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export class TokenAuthServerContextConnector<AuthClaims>
'missing auth context entry',
);
}
if (!auth.startsWith('Bearer ')) {
if (!auth.toString().startsWith('Bearer ')) {
throw new ModuleRpcServer.ServerRpcError(
ModuleRpcCommon.RpcErrorType.unauthenticated,
'Authorization header is not a bearer token',
);
}
const token = auth.replace(/^Bearer\s+/, '');
const token = auth.toString().replace(/^Bearer\s+/, '');
try {
return { authClaims: await this.authClaimsHandler(token) };
} catch (err) {
Expand Down
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export * from './client';
export * from './common';
export * from './context/client';
export * from './context/common';
export * from './context/server';
export * from './protocol/client';
export * from './protocol/grpc_web/client';
export * from './protocol/grpc_web/common';
export * from './protocol/grpc_web/server';
export * from './protocol/mock';
export * from './protocol/server';
export * from './server';
export * from './utils';
2 changes: 1 addition & 1 deletion src/protocol/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface RpcClientOptions {
* The Codec to use. By default, we use the [[GrpcWebJsonCodec]] codec. The Codec must match
* the Codec used by the server (this is enforced through content-type negotiation).
*/
codec?: GrpcWebCodec
codec?: GrpcWebCodec;
}

export function getRpcClient<
Expand Down
10 changes: 8 additions & 2 deletions src/protocol/grpc_web/__tests__/client_server.it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ const serverContextConnector = (
return _.fromPairs(
Utils.entries(encodedRequestContext)
.filter(([key]) => Utils.keys(requestContext).includes(key))
.map(([key, value]) => [key, value.replace(`${key}__`, '')]),
.map(([key, value]) => [key, value.toString().replace(`${key}__`, '')]),
);
},
async provideResponseContext() {
Expand All @@ -671,7 +671,13 @@ const clientContextConnector = (
return _.fromPairs(
Utils.entries(encodedResponseContext)
.filter(([key]) => Utils.keys(responseContext).includes(key))
.map(([key, value]) => [key, value.replace(`${key}__`, '').trim()]),
.map(([key, value]) => [
key,
value
.toString()
.replace(`${key}__`, '')
.trim(),
]),
);
},
});
Expand Down
6 changes: 4 additions & 2 deletions src/protocol/grpc_web/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ class GrpcWebStream<Request, Response, ResponseContext>
switch (chunk.chunkType) {
case ChunkType.MESSAGE:
if (chunk.data) {
const startDecode = Date.now()
const startDecode = Date.now();
const response = this.codec.decodeMessage(this.method, chunk.data);
debugLog(`decodeMessage chunk performance ${Date.now() - startDecode}ms`)
debugLog(
`decodeMessage chunk performance ${Date.now() - startDecode}ms`,
);

this.emit('message', {
response,
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/grpc_web/common/json_codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class GrpcWebJsonCodec implements GrpcWebCodec {
* A Codec that serializes/deserializes messages to and from JSON,
* using gzip for compression.
*/
export class GrpcWebJsonWithGzipCodec implements GrpcWebCodec {
export class GrpcWebJsonWithGzipCodec implements GrpcWebCodec {
/** @override */
getContentType() {
return 'application/grpc-web+json';
Expand Down
21 changes: 12 additions & 9 deletions src/protocol/grpc_web/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,18 @@ export function registerGrpcWebRoutes<
const encodedRequestContext: {
[key: string]: string;
} = ModuleRpcUtils.mapValuesWithStringKeys(
ModuleRpcUtils.filterNonNullValues<string, string[] | string>(
req.headers,
),
ModuleRpcUtils.filterNonNullValues<
string,
string[] | string | number[] | number | undefined
>(req.headers),
value =>
typeof value === 'string'
? decodeHeaderValue(value)
: /* istanbul ignore next */ value
.map(decodeHeaderValue)
.join(','),
typeof value === 'string' || typeof value === 'number'
? decodeHeaderValue(value.toString())
: value
? /* istanbul ignore next */ (value as number[]) // Assume the worst to keep typescript happy
.map(arrValue => decodeHeaderValue(arrValue.toString()))
.join(',')
: '',
);

// Decode the request context and the request
Expand Down Expand Up @@ -503,7 +506,7 @@ async function addEncodedResponseContext<RequestContext>(
);
ModuleRpcUtils.entries(encodedResponseContext).forEach(([key, value]) => {
if (key) {
resp.setHeader(key.toString(), encodeHeaderValue(value));
resp.setHeader(key.toString(), encodeHeaderValue(value.toString()));
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function registerRpcRoutes<
{
router: options.router,
reportError: options.captureError,
codec: options.codec
codec: options.codec,
},
);
}
Loading