GRPCCall+ChannelArg.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. *
  3. * Copyright 2016 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #import "GRPCCall+ChannelArg.h"
  19. #import "private/GRPCHost.h"
  20. #import <grpc/impl/codegen/compression_types.h>
  21. @implementation GRPCCall (ChannelArg)
  22. + (void)setUserAgentPrefix:(nonnull NSString *)userAgentPrefix forHost:(nonnull NSString *)host {
  23. GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
  24. hostConfig.userAgentPrefix = userAgentPrefix;
  25. }
  26. + (void)setResponseSizeLimit:(NSUInteger)limit forHost:(nonnull NSString *)host {
  27. GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
  28. hostConfig.responseSizeLimitOverride = @(limit);
  29. }
  30. + (void)closeOpenConnections {
  31. [GRPCHost flushChannelCache];
  32. }
  33. + (void)setDefaultCompressMethod:(GRPCCompressAlgorithm)algorithm
  34. forhost:(nonnull NSString *)host {
  35. GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
  36. switch (algorithm) {
  37. case GRPCCompressNone:
  38. hostConfig.compressAlgorithm = GRPC_COMPRESS_NONE;
  39. break;
  40. case GRPCCompressDeflate:
  41. hostConfig.compressAlgorithm = GRPC_COMPRESS_MESSAGE_DEFLATE;
  42. break;
  43. case GRPCCompressGzip:
  44. hostConfig.compressAlgorithm = GRPC_COMPRESS_MESSAGE_GZIP;
  45. break;
  46. default:
  47. NSLog(@"Invalid compression algorithm");
  48. abort();
  49. }
  50. }
  51. @end