mirror of https://github.com/grpc/grpc-node.git
have client restore default sendCompression if server doesnt support compression, and fix test file generation
This commit is contained in:
parent
959503ec94
commit
af010071fe
|
|
@ -52,9 +52,10 @@
|
|||
"test": "gulp test",
|
||||
"check": "gts check src/**/*.ts",
|
||||
"fix": "gts fix src/*.ts",
|
||||
"pretest": "npm run generate-types && npm run compile",
|
||||
"pretest": "npm run generate-types && npm run generate-test-types && npm run compile",
|
||||
"posttest": "npm run check && madge -c ./build/src",
|
||||
"generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ --include-dirs test/fixtures/ -O src/generated/ --grpcLib ../index channelz.proto test_service.proto"
|
||||
"generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ --include-dirs test/fixtures/ -O src/generated/ --grpcLib ../index channelz.proto",
|
||||
"generate-test-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --include-dirs test/fixtures/ -O test/generated/ --grpcLib ../../src/index test_service.proto"
|
||||
},
|
||||
"dependencies": {
|
||||
"@grpc/proto-loader": "^0.6.4",
|
||||
|
|
|
|||
|
|
@ -217,6 +217,18 @@ export class CompressionFilter extends BaseFilter implements Filter {
|
|||
}
|
||||
}
|
||||
metadata.remove('grpc-encoding');
|
||||
|
||||
/* Check to see if the compression we're using to send messages is supported by the server
|
||||
* If not, reset the sendCompression filter and have it use the default IdentityHandler */
|
||||
const serverSupportedEncodingsHeader = metadata.get('grpc-accept-encoding')[0] as string | undefined;
|
||||
if (serverSupportedEncodingsHeader) {
|
||||
const serverSupportedEncodings = serverSupportedEncodingsHeader.split(',');
|
||||
|
||||
if ((this.sendCompression instanceof DeflateHandler && !serverSupportedEncodings.includes('deflate'))
|
||||
|| (this.sendCompression instanceof GzipHandler && !serverSupportedEncodings.includes('gzip'))) {
|
||||
this.sendCompression = new IdentityHandler();
|
||||
}
|
||||
}
|
||||
metadata.remove('grpc-accept-encoding');
|
||||
return metadata;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Original file: test/fixtures/test_service.proto
|
||||
|
||||
import type * as grpc from './../index'
|
||||
import type * as grpc from './../../src/index'
|
||||
import type { MethodDefinition } from '@grpc/proto-loader'
|
||||
import type { Request as _Request, Request__Output as _Request__Output } from './Request';
|
||||
import type { Response as _Response, Response__Output as _Response__Output } from './Response';
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import type * as grpc from '../index';
|
||||
import type * as grpc from '../../src/index';
|
||||
import type { MessageTypeDefinition } from '@grpc/proto-loader';
|
||||
|
||||
import type { TestServiceClient as _TestServiceClient, TestServiceDefinition as _TestServiceDefinition } from './TestService';
|
||||
|
|
@ -30,11 +30,11 @@ import { ServiceClient, ServiceClientConstructor } from '../src/make-client';
|
|||
import { sendUnaryData, ServerUnaryCall } from '../src/server-call';
|
||||
|
||||
import { loadProtoFile } from './common';
|
||||
import { TestServiceClient, TestServiceHandlers } from '../src/generated/TestService';
|
||||
import { ProtoGrpcType as TestServiceGrpcType } from '../src/generated/test_service';
|
||||
import { Request__Output } from '../src/generated/Request';
|
||||
import { TestServiceClient, TestServiceHandlers } from './generated/TestService';
|
||||
import { ProtoGrpcType as TestServiceGrpcType } from './generated/test_service';
|
||||
import { Request__Output } from './generated/Request';
|
||||
|
||||
const loadedTestServiceProto = protoLoader.loadSync('test_service.proto', {
|
||||
const loadedTestServiceProto = protoLoader.loadSync('test/fixtures/test_service.proto', {
|
||||
keepCase: true,
|
||||
longs: String,
|
||||
enums: String,
|
||||
|
|
@ -849,20 +849,5 @@ describe('Compressed requests', () => {
|
|||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Should fail when attempting to use an unsupported compression method', done => {
|
||||
client = new testServiceGrpcObject.TestService(
|
||||
`localhost:${assignedPort}`,
|
||||
grpc.credentials.createInsecure(),
|
||||
{
|
||||
'grpc.default_compression_algorithm': 3
|
||||
}
|
||||
);
|
||||
|
||||
client.unary({ message: 'foo' }, (err, response) => {
|
||||
assert.ok(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue