grpc 1.1.2 → 1.2.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1257 -404
  3. data/etc/roots.pem +189 -102
  4. data/include/grpc/census.h +7 -7
  5. data/include/grpc/compression.h +4 -4
  6. data/include/grpc/grpc.h +13 -7
  7. data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
  8. data/include/grpc/impl/codegen/grpc_types.h +39 -30
  9. data/include/grpc/impl/codegen/slice.h +24 -6
  10. data/include/grpc/impl/codegen/sync.h +8 -0
  11. data/include/grpc/load_reporting.h +63 -0
  12. data/include/grpc/slice.h +37 -1
  13. data/include/grpc/slice_buffer.h +7 -0
  14. data/include/grpc/support/alloc.h +3 -0
  15. data/include/grpc/support/useful.h +3 -0
  16. data/src/core/ext/census/gen/census.pb.h +1 -1
  17. data/src/core/ext/census/gen/trace_context.pb.c +9 -36
  18. data/src/core/ext/census/gen/trace_context.pb.h +20 -26
  19. data/src/core/ext/census/grpc_filter.c +3 -5
  20. data/src/core/ext/census/trace_context.c +1 -1
  21. data/src/core/ext/census/trace_context.h +3 -0
  22. data/src/core/ext/census/trace_label.h +61 -0
  23. data/src/core/ext/census/trace_propagation.h +63 -0
  24. data/src/core/ext/census/trace_status.h +45 -0
  25. data/src/core/ext/census/trace_string.h +50 -0
  26. data/src/core/ext/census/tracing.c +31 -11
  27. data/src/core/ext/census/tracing.h +124 -0
  28. data/src/core/ext/client_channel/client_channel.c +456 -368
  29. data/src/core/ext/client_channel/client_channel.h +4 -0
  30. data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
  31. data/src/core/ext/client_channel/connector.c +3 -3
  32. data/src/core/ext/client_channel/connector.h +4 -3
  33. data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
  34. data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
  35. data/src/core/ext/client_channel/http_proxy.c +125 -0
  36. data/src/core/ext/client_channel/http_proxy.h +39 -0
  37. data/src/core/ext/client_channel/lb_policy.c +56 -35
  38. data/src/core/ext/client_channel/lb_policy.h +46 -39
  39. data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
  40. data/src/core/ext/client_channel/parse_address.c +32 -6
  41. data/src/core/ext/client_channel/proxy_mapper.c +63 -0
  42. data/src/core/ext/client_channel/proxy_mapper.h +89 -0
  43. data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
  44. data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
  45. data/src/core/ext/client_channel/resolver.c +16 -9
  46. data/src/core/ext/client_channel/resolver.h +23 -12
  47. data/src/core/ext/client_channel/resolver_factory.h +1 -0
  48. data/src/core/ext/client_channel/resolver_registry.c +15 -11
  49. data/src/core/ext/client_channel/resolver_registry.h +5 -3
  50. data/src/core/ext/client_channel/subchannel.c +44 -27
  51. data/src/core/ext/client_channel/subchannel.h +6 -2
  52. data/src/core/ext/client_channel/uri_parser.c +26 -14
  53. data/src/core/ext/client_channel/uri_parser.h +3 -1
  54. data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
  55. data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
  56. data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
  57. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
  58. data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
  59. data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
  60. data/src/core/ext/load_reporting/load_reporting.c +20 -0
  61. data/src/core/ext/load_reporting/load_reporting.h +1 -16
  62. data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
  63. data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
  64. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
  65. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
  67. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
  68. data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
  69. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
  70. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
  71. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
  72. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
  73. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
  74. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
  75. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
  76. data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
  77. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
  78. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
  79. data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
  80. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
  81. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
  84. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
  86. data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
  87. data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
  88. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
  89. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
  90. data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
  91. data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
  92. data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
  93. data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
  94. data/src/core/lib/channel/channel_stack.c +14 -44
  95. data/src/core/lib/channel/channel_stack.h +10 -17
  96. data/src/core/lib/channel/channel_stack_builder.c +2 -3
  97. data/src/core/lib/channel/compress_filter.c +54 -46
  98. data/src/core/lib/channel/connected_channel.c +4 -4
  99. data/src/core/lib/channel/connected_channel.h +5 -0
  100. data/src/core/lib/channel/context.h +3 -0
  101. data/src/core/lib/channel/deadline_filter.c +61 -61
  102. data/src/core/lib/channel/deadline_filter.h +8 -5
  103. data/src/core/lib/channel/handshaker.c +47 -7
  104. data/src/core/lib/channel/handshaker.h +21 -3
  105. data/src/core/lib/channel/http_client_filter.c +149 -99
  106. data/src/core/lib/channel/http_server_filter.c +163 -147
  107. data/src/core/lib/channel/message_size_filter.c +15 -10
  108. data/src/core/lib/compression/algorithm_metadata.h +4 -4
  109. data/src/core/lib/compression/compression.c +17 -23
  110. data/src/core/lib/http/httpcli.c +3 -2
  111. data/src/core/lib/http/httpcli.h +2 -1
  112. data/src/core/lib/http/httpcli_security_connector.c +2 -3
  113. data/src/core/lib/http/parser.c +2 -2
  114. data/src/core/lib/iomgr/closure.c +6 -3
  115. data/src/core/lib/iomgr/closure.h +4 -2
  116. data/src/core/lib/iomgr/combiner.c +35 -5
  117. data/src/core/lib/iomgr/combiner.h +21 -2
  118. data/src/core/lib/iomgr/endpoint.c +3 -2
  119. data/src/core/lib/iomgr/endpoint.h +3 -2
  120. data/src/core/lib/iomgr/error.c +60 -94
  121. data/src/core/lib/iomgr/error.h +7 -10
  122. data/src/core/lib/iomgr/error_internal.h +54 -0
  123. data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
  124. data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
  125. data/src/core/lib/iomgr/ev_posix.c +7 -8
  126. data/src/core/lib/iomgr/ev_posix.h +4 -4
  127. data/src/core/lib/iomgr/exec_ctx.c +11 -6
  128. data/src/core/lib/iomgr/exec_ctx.h +11 -14
  129. data/src/core/lib/iomgr/executor.c +2 -2
  130. data/src/core/lib/iomgr/load_file.c +1 -1
  131. data/src/core/lib/iomgr/network_status_tracker.c +5 -81
  132. data/src/core/lib/iomgr/pollset.h +1 -3
  133. data/src/core/lib/iomgr/pollset_set.h +2 -1
  134. data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
  135. data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
  136. data/src/core/lib/iomgr/pollset_uv.c +25 -11
  137. data/src/core/lib/iomgr/pollset_windows.c +0 -11
  138. data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
  139. data/src/core/lib/iomgr/resource_quota.c +41 -11
  140. data/src/core/lib/iomgr/resource_quota.h +6 -0
  141. data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
  142. data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
  143. data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
  144. data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
  145. data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
  146. data/src/core/lib/iomgr/tcp_posix.c +4 -5
  147. data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
  148. data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
  149. data/src/core/lib/iomgr/tcp_uv.c +11 -5
  150. data/src/core/lib/iomgr/tcp_windows.c +20 -7
  151. data/src/core/lib/iomgr/timer_generic.c +15 -22
  152. data/src/core/lib/iomgr/timer_generic.h +1 -1
  153. data/src/core/lib/iomgr/timer_uv.c +10 -6
  154. data/src/core/lib/iomgr/timer_uv.h +1 -1
  155. data/src/core/lib/iomgr/udp_server.c +45 -6
  156. data/src/core/lib/iomgr/udp_server.h +7 -1
  157. data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
  158. data/src/core/lib/json/json.c +1 -2
  159. data/src/core/lib/profiling/basic_timers.c +17 -3
  160. data/src/core/lib/security/context/security_context.c +3 -10
  161. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
  162. data/src/core/lib/security/credentials/credentials.c +48 -2
  163. data/src/core/lib/security/credentials/credentials.h +13 -0
  164. data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
  165. data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
  166. data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
  167. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
  168. data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
  169. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
  170. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
  171. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  172. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
  173. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
  174. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
  175. data/src/core/lib/security/transport/client_auth_filter.c +72 -47
  176. data/src/core/lib/security/transport/lb_targets_info.c +70 -0
  177. data/src/core/lib/security/transport/lb_targets_info.h +47 -0
  178. data/src/core/lib/security/transport/secure_endpoint.c +3 -3
  179. data/src/core/lib/security/transport/security_connector.c +125 -28
  180. data/src/core/lib/security/transport/security_connector.h +4 -3
  181. data/src/core/lib/security/transport/security_handshaker.c +13 -9
  182. data/src/core/lib/security/transport/server_auth_filter.c +31 -40
  183. data/src/core/lib/security/util/b64.c +1 -1
  184. data/src/core/lib/slice/slice.c +110 -20
  185. data/src/core/lib/slice/slice_buffer.c +92 -39
  186. data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
  187. data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
  188. data/src/core/lib/slice/slice_intern.c +346 -0
  189. data/src/core/lib/slice/slice_internal.h +15 -0
  190. data/src/core/lib/slice/slice_string_helpers.c +5 -0
  191. data/src/core/lib/slice/slice_string_helpers.h +5 -0
  192. data/src/core/lib/support/alloc.c +26 -1
  193. data/src/core/lib/support/cmdline.c +2 -4
  194. data/src/core/lib/support/cpu_posix.c +2 -7
  195. data/src/core/lib/support/histogram.c +1 -2
  196. data/src/core/lib/support/log_posix.c +8 -4
  197. data/src/core/lib/support/spinlock.h +52 -0
  198. data/src/core/lib/support/subprocess_posix.c +1 -2
  199. data/src/core/lib/support/sync.c +7 -1
  200. data/src/core/lib/support/sync_posix.c +9 -0
  201. data/src/core/lib/support/time_windows.c +7 -1
  202. data/src/core/lib/surface/call.c +647 -629
  203. data/src/core/lib/surface/call.h +4 -1
  204. data/src/core/lib/surface/call_details.c +8 -2
  205. data/src/core/lib/surface/call_log_batch.c +17 -6
  206. data/src/core/lib/surface/channel.c +49 -59
  207. data/src/core/lib/surface/channel.h +5 -6
  208. data/src/core/lib/surface/completion_queue.c +16 -45
  209. data/src/core/lib/surface/completion_queue.h +0 -3
  210. data/src/core/lib/surface/init.c +6 -2
  211. data/src/core/lib/surface/init_secure.c +1 -1
  212. data/src/core/lib/surface/lame_client.c +14 -4
  213. data/src/core/lib/surface/server.c +79 -82
  214. data/src/core/lib/surface/validate_metadata.c +46 -15
  215. data/src/core/lib/surface/validate_metadata.h +43 -0
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.c +104 -0
  218. data/src/core/lib/transport/bdp_estimator.h +76 -0
  219. data/src/core/lib/transport/connectivity_state.c +33 -13
  220. data/src/core/lib/transport/connectivity_state.h +15 -5
  221. data/src/core/lib/transport/error_utils.c +124 -0
  222. data/src/core/lib/transport/error_utils.h +56 -0
  223. data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
  224. data/src/core/lib/transport/metadata.c +259 -503
  225. data/src/core/lib/transport/metadata.h +69 -68
  226. data/src/core/lib/transport/metadata_batch.c +183 -63
  227. data/src/core/lib/transport/metadata_batch.h +50 -26
  228. data/src/core/lib/transport/pid_controller.c +28 -8
  229. data/src/core/lib/transport/pid_controller.h +15 -2
  230. data/src/core/lib/transport/service_config.c +21 -18
  231. data/src/core/lib/transport/service_config.h +5 -5
  232. data/src/core/lib/transport/static_metadata.c +753 -112
  233. data/src/core/lib/transport/static_metadata.h +403 -264
  234. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
  235. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
  236. data/src/core/lib/transport/timeout_encoding.c +11 -9
  237. data/src/core/lib/transport/timeout_encoding.h +3 -1
  238. data/src/core/lib/transport/transport.c +47 -87
  239. data/src/core/lib/transport/transport.h +20 -25
  240. data/src/core/lib/transport/transport_op_string.c +7 -19
  241. data/src/core/lib/tsi/fake_transport_security.c +2 -4
  242. data/src/core/lib/tsi/ssl_transport_security.c +7 -16
  243. data/src/core/lib/tsi/transport_security.c +2 -4
  244. data/src/ruby/ext/grpc/extconf.rb +4 -1
  245. data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
  246. data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
  247. data/src/ruby/ext/grpc/rb_call.c +47 -46
  248. data/src/ruby/ext/grpc/rb_channel.c +21 -6
  249. data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
  250. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
  251. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
  252. data/src/ruby/ext/grpc/rb_server.c +6 -4
  253. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  254. data/src/ruby/lib/grpc/version.rb +1 -1
  255. metadata +33 -9
@@ -39,6 +39,7 @@
39
39
  #include "src/core/lib/profiling/timers.h"
40
40
  #include "src/core/lib/slice/percent_encoding.h"
41
41
  #include "src/core/lib/slice/slice_internal.h"
42
+ #include "src/core/lib/slice/slice_string_helpers.h"
42
43
  #include "src/core/lib/transport/static_metadata.h"
43
44
 
44
45
  #define EXPECTED_CONTENT_TYPE "application/grpc"
@@ -47,18 +48,13 @@
47
48
  extern int grpc_http_trace;
48
49
 
49
50
  typedef struct call_data {
50
- uint8_t seen_path;
51
- uint8_t seen_method;
52
- uint8_t sent_status;
53
- uint8_t seen_scheme;
54
- uint8_t seen_te_trailers;
55
- uint8_t seen_authority;
56
- uint8_t seen_payload_bin;
57
51
  grpc_linked_mdelem status;
58
52
  grpc_linked_mdelem content_type;
59
53
 
54
+ /* did this request come with payload-bin */
55
+ bool seen_payload_bin;
60
56
  /* flag to ensure payload_bin is delivered only once */
61
- uint8_t payload_bin_delivered;
57
+ bool payload_bin_delivered;
62
58
 
63
59
  grpc_metadata_batch *recv_initial_metadata;
64
60
  bool *recv_idempotent_request;
@@ -83,109 +79,155 @@ typedef struct call_data {
83
79
 
84
80
  typedef struct channel_data { uint8_t unused; } channel_data;
85
81
 
86
- static grpc_mdelem *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx,
87
- void *user_data,
88
- grpc_mdelem *md) {
89
- if (md->key == GRPC_MDSTR_GRPC_MESSAGE) {
82
+ static grpc_error *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx,
83
+ grpc_call_element *elem,
84
+ grpc_metadata_batch *b) {
85
+ if (b->idx.named.grpc_message != NULL) {
90
86
  grpc_slice pct_encoded_msg = grpc_percent_encode_slice(
91
- md->value->slice, grpc_compatible_percent_encoding_unreserved_bytes);
92
- if (grpc_slice_is_equivalent(pct_encoded_msg, md->value->slice)) {
87
+ GRPC_MDVALUE(b->idx.named.grpc_message->md),
88
+ grpc_compatible_percent_encoding_unreserved_bytes);
89
+ if (grpc_slice_is_equivalent(pct_encoded_msg,
90
+ GRPC_MDVALUE(b->idx.named.grpc_message->md))) {
93
91
  grpc_slice_unref_internal(exec_ctx, pct_encoded_msg);
94
- return md;
95
92
  } else {
96
- return grpc_mdelem_from_metadata_strings(
97
- exec_ctx, GRPC_MDSTR_GRPC_MESSAGE,
98
- grpc_mdstr_from_slice(exec_ctx, pct_encoded_msg));
93
+ grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message,
94
+ pct_encoded_msg);
99
95
  }
100
- } else {
101
- return md;
102
96
  }
97
+ return GRPC_ERROR_NONE;
103
98
  }
104
99
 
105
- static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data,
106
- grpc_mdelem *md) {
107
- grpc_call_element *elem = user_data;
100
+ static void add_error(const char *error_name, grpc_error **cumulative,
101
+ grpc_error *new) {
102
+ if (new == GRPC_ERROR_NONE) return;
103
+ if (*cumulative == GRPC_ERROR_NONE) {
104
+ *cumulative = GRPC_ERROR_CREATE(error_name);
105
+ }
106
+ *cumulative = grpc_error_add_child(*cumulative, new);
107
+ }
108
+
109
+ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx,
110
+ grpc_call_element *elem,
111
+ grpc_metadata_batch *b) {
108
112
  call_data *calld = elem->call_data;
113
+ grpc_error *error = GRPC_ERROR_NONE;
114
+ static const char *error_name = "Failed processing incoming headers";
109
115
 
110
- /* Check if it is one of the headers we care about. */
111
- if (md == GRPC_MDELEM_TE_TRAILERS || md == GRPC_MDELEM_METHOD_POST ||
112
- md == GRPC_MDELEM_METHOD_PUT || md == GRPC_MDELEM_METHOD_GET ||
113
- md == GRPC_MDELEM_SCHEME_HTTP || md == GRPC_MDELEM_SCHEME_HTTPS ||
114
- md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) {
115
- /* swallow it */
116
- if (md == GRPC_MDELEM_METHOD_POST) {
117
- calld->seen_method = 1;
116
+ if (b->idx.named.method != NULL) {
117
+ if (grpc_mdelem_eq(b->idx.named.method->md, GRPC_MDELEM_METHOD_POST)) {
118
118
  *calld->recv_idempotent_request = false;
119
119
  *calld->recv_cacheable_request = false;
120
- } else if (md == GRPC_MDELEM_METHOD_PUT) {
121
- calld->seen_method = 1;
120
+ } else if (grpc_mdelem_eq(b->idx.named.method->md,
121
+ GRPC_MDELEM_METHOD_PUT)) {
122
122
  *calld->recv_idempotent_request = true;
123
- } else if (md == GRPC_MDELEM_METHOD_GET) {
124
- calld->seen_method = 1;
123
+ } else if (grpc_mdelem_eq(b->idx.named.method->md,
124
+ GRPC_MDELEM_METHOD_GET)) {
125
125
  *calld->recv_cacheable_request = true;
126
- } else if (md->key == GRPC_MDSTR_SCHEME) {
127
- calld->seen_scheme = 1;
128
- } else if (md == GRPC_MDELEM_TE_TRAILERS) {
129
- calld->seen_te_trailers = 1;
130
- }
131
- /* TODO(klempner): Track that we've seen all the headers we should
132
- require */
133
- return NULL;
134
- } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) {
135
- const char *value_str = grpc_mdstr_as_c_string(md->value);
136
- if (strncmp(value_str, EXPECTED_CONTENT_TYPE,
137
- EXPECTED_CONTENT_TYPE_LENGTH) == 0 &&
138
- (value_str[EXPECTED_CONTENT_TYPE_LENGTH] == '+' ||
139
- value_str[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) {
140
- /* Although the C implementation doesn't (currently) generate them,
141
- any custom +-suffix is explicitly valid. */
142
- /* TODO(klempner): We should consider preallocating common values such
143
- as +proto or +json, or at least stashing them if we see them. */
144
- /* TODO(klempner): Should we be surfacing this to application code? */
145
126
  } else {
146
- /* TODO(klempner): We're currently allowing this, but we shouldn't
147
- see it without a proxy so log for now. */
148
- gpr_log(GPR_INFO, "Unexpected content-type '%s'", value_str);
127
+ add_error(error_name, &error,
128
+ grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"),
129
+ b->idx.named.method->md));
130
+ }
131
+ grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.method);
132
+ } else {
133
+ add_error(error_name, &error,
134
+ grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"),
135
+ GRPC_ERROR_STR_KEY, ":method"));
136
+ }
137
+
138
+ if (b->idx.named.te != NULL) {
139
+ if (!grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_TE_TRAILERS)) {
140
+ add_error(error_name, &error,
141
+ grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"),
142
+ b->idx.named.te->md));
143
+ }
144
+ grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.te);
145
+ } else {
146
+ add_error(error_name, &error,
147
+ grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"),
148
+ GRPC_ERROR_STR_KEY, "te"));
149
+ }
150
+
151
+ if (b->idx.named.scheme != NULL) {
152
+ if (!grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTP) &&
153
+ !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTPS) &&
154
+ !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_GRPC)) {
155
+ add_error(error_name, &error,
156
+ grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"),
157
+ b->idx.named.scheme->md));
149
158
  }
150
- return NULL;
151
- } else if (md->key == GRPC_MDSTR_TE || md->key == GRPC_MDSTR_METHOD ||
152
- md->key == GRPC_MDSTR_SCHEME) {
153
- gpr_log(GPR_ERROR, "Invalid %s: header: '%s'",
154
- grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value));
155
- /* swallow it and error everything out. */
156
- /* TODO(klempner): We ought to generate more descriptive error messages
157
- on the wire here. */
158
- grpc_call_element_send_cancel(exec_ctx, elem);
159
- return NULL;
160
- } else if (md->key == GRPC_MDSTR_PATH) {
161
- if (calld->seen_path) {
162
- gpr_log(GPR_ERROR, "Received :path twice");
163
- return NULL;
159
+ grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.scheme);
160
+ } else {
161
+ add_error(error_name, &error,
162
+ grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"),
163
+ GRPC_ERROR_STR_KEY, ":scheme"));
164
+ }
165
+
166
+ if (b->idx.named.content_type != NULL) {
167
+ if (!grpc_mdelem_eq(b->idx.named.content_type->md,
168
+ GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) {
169
+ if (grpc_slice_buf_start_eq(GRPC_MDVALUE(b->idx.named.content_type->md),
170
+ EXPECTED_CONTENT_TYPE,
171
+ EXPECTED_CONTENT_TYPE_LENGTH) &&
172
+ (GRPC_SLICE_START_PTR(GRPC_MDVALUE(
173
+ b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] ==
174
+ '+' ||
175
+ GRPC_SLICE_START_PTR(GRPC_MDVALUE(
176
+ b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] ==
177
+ ';')) {
178
+ /* Although the C implementation doesn't (currently) generate them,
179
+ any custom +-suffix is explicitly valid. */
180
+ /* TODO(klempner): We should consider preallocating common values such
181
+ as +proto or +json, or at least stashing them if we see them. */
182
+ /* TODO(klempner): Should we be surfacing this to application code? */
183
+ } else {
184
+ /* TODO(klempner): We're currently allowing this, but we shouldn't
185
+ see it without a proxy so log for now. */
186
+ char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md),
187
+ GPR_DUMP_ASCII);
188
+ gpr_log(GPR_INFO, "Unexpected content-type '%s'", val);
189
+ gpr_free(val);
190
+ }
164
191
  }
165
- calld->seen_path = 1;
166
- return md;
167
- } else if (md->key == GRPC_MDSTR_AUTHORITY) {
168
- calld->seen_authority = 1;
169
- return md;
170
- } else if (md->key == GRPC_MDSTR_HOST) {
171
- /* translate host to :authority since :authority may be
172
- omitted */
173
- grpc_mdelem *authority = grpc_mdelem_from_metadata_strings(
174
- exec_ctx, GRPC_MDSTR_AUTHORITY, GRPC_MDSTR_REF(md->value));
175
- calld->seen_authority = 1;
176
- return authority;
177
- } else if (md->key == GRPC_MDSTR_GRPC_PAYLOAD_BIN) {
178
- /* Retrieve the payload from the value of the 'grpc-internal-payload-bin'
179
- header field */
180
- calld->seen_payload_bin = 1;
192
+ grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type);
193
+ }
194
+
195
+ if (b->idx.named.path == NULL) {
196
+ add_error(error_name, &error,
197
+ grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"),
198
+ GRPC_ERROR_STR_KEY, ":path"));
199
+ }
200
+
201
+ if (b->idx.named.host != NULL && b->idx.named.authority == NULL) {
202
+ grpc_linked_mdelem *el = b->idx.named.host;
203
+ grpc_mdelem md = GRPC_MDELEM_REF(el->md);
204
+ grpc_metadata_batch_remove(exec_ctx, b, el);
205
+ add_error(
206
+ error_name, &error,
207
+ grpc_metadata_batch_add_head(
208
+ exec_ctx, b, el, grpc_mdelem_from_slices(
209
+ exec_ctx, GRPC_MDSTR_AUTHORITY,
210
+ grpc_slice_ref_internal(GRPC_MDVALUE(md)))));
211
+ GRPC_MDELEM_UNREF(exec_ctx, md);
212
+ }
213
+
214
+ if (b->idx.named.authority == NULL) {
215
+ add_error(error_name, &error,
216
+ grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"),
217
+ GRPC_ERROR_STR_KEY, ":authority"));
218
+ }
219
+
220
+ if (b->idx.named.grpc_payload_bin != NULL) {
221
+ calld->seen_payload_bin = true;
181
222
  grpc_slice_buffer_add(&calld->read_slice_buffer,
182
- grpc_slice_ref_internal(md->value->slice));
223
+ grpc_slice_ref_internal(
224
+ GRPC_MDVALUE(b->idx.named.grpc_payload_bin->md)));
183
225
  grpc_slice_buffer_stream_init(&calld->read_stream,
184
226
  &calld->read_slice_buffer, 0);
185
- return NULL;
186
- } else {
187
- return md;
227
+ grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_payload_bin);
188
228
  }
229
+
230
+ return error;
189
231
  }
190
232
 
191
233
  static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data,
@@ -193,49 +235,12 @@ static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data,
193
235
  grpc_call_element *elem = user_data;
194
236
  call_data *calld = elem->call_data;
195
237
  if (err == GRPC_ERROR_NONE) {
196
- grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata,
197
- server_filter, elem);
198
- /* Have we seen the required http2 transport headers?
199
- (:method, :scheme, content-type, with :path and :authority covered
200
- at the channel level right now) */
201
- if (calld->seen_method && calld->seen_scheme && calld->seen_te_trailers &&
202
- calld->seen_path && calld->seen_authority) {
203
- /* do nothing */
204
- } else {
205
- err = GRPC_ERROR_CREATE("Bad incoming HTTP headers");
206
- if (!calld->seen_path) {
207
- err = grpc_error_add_child(err,
208
- GRPC_ERROR_CREATE("Missing :path header"));
209
- }
210
- if (!calld->seen_authority) {
211
- err = grpc_error_add_child(
212
- err, GRPC_ERROR_CREATE("Missing :authority header"));
213
- }
214
- if (!calld->seen_method) {
215
- err = grpc_error_add_child(err,
216
- GRPC_ERROR_CREATE("Missing :method header"));
217
- }
218
- if (!calld->seen_scheme) {
219
- err = grpc_error_add_child(err,
220
- GRPC_ERROR_CREATE("Missing :scheme header"));
221
- }
222
- if (!calld->seen_te_trailers) {
223
- err = grpc_error_add_child(
224
- err, GRPC_ERROR_CREATE("Missing te: trailers header"));
225
- }
226
- /* Error this call out */
227
- if (grpc_http_trace) {
228
- const char *error_str = grpc_error_string(err);
229
- gpr_log(GPR_ERROR, "Invalid http2 headers: %s", error_str);
230
- grpc_error_free_string(error_str);
231
- }
232
- grpc_call_element_send_cancel(exec_ctx, elem);
233
- }
238
+ err = server_filter_incoming_metadata(exec_ctx, elem,
239
+ calld->recv_initial_metadata);
234
240
  } else {
235
241
  GRPC_ERROR_REF(err);
236
242
  }
237
- calld->on_done_recv->cb(exec_ctx, calld->on_done_recv->cb_arg, err);
238
- GRPC_ERROR_UNREF(err);
243
+ grpc_closure_run(exec_ctx, calld->on_done_recv, err);
239
244
  }
240
245
 
241
246
  static void hs_on_complete(grpc_exec_ctx *exec_ctx, void *user_data,
@@ -247,12 +252,11 @@ static void hs_on_complete(grpc_exec_ctx *exec_ctx, void *user_data,
247
252
  *calld->pp_recv_message = calld->payload_bin_delivered
248
253
  ? NULL
249
254
  : (grpc_byte_stream *)&calld->read_stream;
250
- calld->recv_message_ready->cb(exec_ctx, calld->recv_message_ready->cb_arg,
251
- err);
255
+ grpc_closure_run(exec_ctx, calld->recv_message_ready, GRPC_ERROR_REF(err));
252
256
  calld->recv_message_ready = NULL;
253
257
  calld->payload_bin_delivered = true;
254
258
  }
255
- calld->on_complete->cb(exec_ctx, calld->on_complete->cb_arg, err);
259
+ grpc_closure_run(exec_ctx, calld->on_complete, GRPC_ERROR_REF(err));
256
260
  }
257
261
 
258
262
  static void hs_recv_message_ready(grpc_exec_ctx *exec_ctx, void *user_data,
@@ -263,8 +267,7 @@ static void hs_recv_message_ready(grpc_exec_ctx *exec_ctx, void *user_data,
263
267
  /* do nothing. This is probably a GET request, and payload will be returned
264
268
  in hs_on_complete callback. */
265
269
  } else {
266
- calld->recv_message_ready->cb(exec_ctx, calld->recv_message_ready->cb_arg,
267
- err);
270
+ grpc_closure_run(exec_ctx, calld->recv_message_ready, GRPC_ERROR_REF(err));
268
271
  }
269
272
  }
270
273
 
@@ -273,13 +276,23 @@ static void hs_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
273
276
  /* grab pointers to our data from the call element */
274
277
  call_data *calld = elem->call_data;
275
278
 
276
- if (op->send_initial_metadata != NULL && !calld->sent_status) {
277
- calld->sent_status = 1;
278
- grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->status,
279
- GRPC_MDELEM_STATUS_200);
280
- grpc_metadata_batch_add_tail(
281
- op->send_initial_metadata, &calld->content_type,
282
- GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC);
279
+ if (op->send_initial_metadata != NULL) {
280
+ grpc_error *error = GRPC_ERROR_NONE;
281
+ static const char *error_name = "Failed sending initial metadata";
282
+ add_error(error_name, &error, grpc_metadata_batch_add_head(
283
+ exec_ctx, op->send_initial_metadata,
284
+ &calld->status, GRPC_MDELEM_STATUS_200));
285
+ add_error(error_name, &error,
286
+ grpc_metadata_batch_add_tail(
287
+ exec_ctx, op->send_initial_metadata, &calld->content_type,
288
+ GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC));
289
+ add_error(error_name, &error,
290
+ server_filter_outgoing_metadata(exec_ctx, elem,
291
+ op->send_initial_metadata));
292
+ if (error != GRPC_ERROR_NONE) {
293
+ grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error);
294
+ return;
295
+ }
283
296
  }
284
297
 
285
298
  if (op->recv_initial_metadata) {
@@ -306,8 +319,12 @@ static void hs_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
306
319
  }
307
320
 
308
321
  if (op->send_trailing_metadata) {
309
- grpc_metadata_batch_filter(exec_ctx, op->send_trailing_metadata,
310
- server_filter_outgoing_metadata, elem);
322
+ grpc_error *error = server_filter_outgoing_metadata(
323
+ exec_ctx, elem, op->send_trailing_metadata);
324
+ if (error != GRPC_ERROR_NONE) {
325
+ grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error);
326
+ return;
327
+ }
311
328
  }
312
329
  }
313
330
 
@@ -324,11 +341,10 @@ static void hs_start_transport_op(grpc_exec_ctx *exec_ctx,
324
341
  /* Constructor for call_data */
325
342
  static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
326
343
  grpc_call_element *elem,
327
- grpc_call_element_args *args) {
344
+ const grpc_call_element_args *args) {
328
345
  /* grab pointers to our data from the call element */
329
346
  call_data *calld = elem->call_data;
330
347
  /* initialize members */
331
- memset(calld, 0, sizeof(*calld));
332
348
  grpc_closure_init(&calld->hs_on_recv, hs_on_recv, elem,
333
349
  grpc_schedule_on_exec_ctx);
334
350
  grpc_closure_init(&calld->hs_on_complete, hs_on_complete, elem,
@@ -58,7 +58,7 @@ static void message_size_limits_free(grpc_exec_ctx* exec_ctx, void* value) {
58
58
  gpr_free(value);
59
59
  }
60
60
 
61
- static const grpc_mdstr_hash_table_vtable message_size_limits_vtable = {
61
+ static const grpc_slice_hash_table_vtable message_size_limits_vtable = {
62
62
  message_size_limits_free, message_size_limits_copy};
63
63
 
64
64
  static void* message_size_limits_create_from_json(const grpc_json* json) {
@@ -68,12 +68,16 @@ static void* message_size_limits_create_from_json(const grpc_json* json) {
68
68
  if (field->key == NULL) continue;
69
69
  if (strcmp(field->key, "maxRequestMessageBytes") == 0) {
70
70
  if (max_request_message_bytes >= 0) return NULL; // Duplicate.
71
- if (field->type != GRPC_JSON_STRING) return NULL;
71
+ if (field->type != GRPC_JSON_STRING && field->type != GRPC_JSON_NUMBER) {
72
+ return NULL;
73
+ }
72
74
  max_request_message_bytes = gpr_parse_nonnegative_int(field->value);
73
75
  if (max_request_message_bytes == -1) return NULL;
74
76
  } else if (strcmp(field->key, "maxResponseMessageBytes") == 0) {
75
77
  if (max_response_message_bytes >= 0) return NULL; // Duplicate.
76
- if (field->type != GRPC_JSON_STRING) return NULL;
78
+ if (field->type != GRPC_JSON_STRING && field->type != GRPC_JSON_NUMBER) {
79
+ return NULL;
80
+ }
77
81
  max_response_message_bytes = gpr_parse_nonnegative_int(field->value);
78
82
  if (max_response_message_bytes == -1) return NULL;
79
83
  }
@@ -101,7 +105,7 @@ typedef struct channel_data {
101
105
  int max_send_size;
102
106
  int max_recv_size;
103
107
  // Maps path names to message_size_limits structs.
104
- grpc_mdstr_hash_table* method_limit_table;
108
+ grpc_slice_hash_table* method_limit_table;
105
109
  } channel_data;
106
110
 
107
111
  // Callback invoked when we receive a message. Here we check the max
@@ -142,10 +146,12 @@ static void start_transport_stream_op(grpc_exec_ctx* exec_ctx,
142
146
  char* message_string;
143
147
  gpr_asprintf(&message_string, "Sent message larger than max (%u vs. %d)",
144
148
  op->send_message->length, calld->max_send_size);
145
- grpc_slice message = grpc_slice_from_copied_string(message_string);
149
+ grpc_transport_stream_op_finish_with_failure(
150
+ exec_ctx, op, grpc_error_set_int(GRPC_ERROR_CREATE(message_string),
151
+ GRPC_ERROR_INT_GRPC_STATUS,
152
+ GRPC_STATUS_INVALID_ARGUMENT));
146
153
  gpr_free(message_string);
147
- grpc_call_element_send_close_with_message(
148
- exec_ctx, elem, GRPC_STATUS_INVALID_ARGUMENT, &message);
154
+ return;
149
155
  }
150
156
  // Inject callback for receiving a message.
151
157
  if (op->recv_message_ready != NULL) {
@@ -160,7 +166,7 @@ static void start_transport_stream_op(grpc_exec_ctx* exec_ctx,
160
166
  // Constructor for call_data.
161
167
  static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx,
162
168
  grpc_call_element* elem,
163
- grpc_call_element_args* args) {
169
+ const grpc_call_element_args* args) {
164
170
  channel_data* chand = elem->channel_data;
165
171
  call_data* calld = elem->call_data;
166
172
  calld->next_recv_message_ready = NULL;
@@ -202,7 +208,6 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx,
202
208
  grpc_channel_element_args* args) {
203
209
  GPR_ASSERT(!args->is_last);
204
210
  channel_data* chand = elem->channel_data;
205
- memset(chand, 0, sizeof(*chand));
206
211
  chand->max_send_size = GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH;
207
212
  chand->max_recv_size = GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH;
208
213
  for (size_t i = 0; i < args->channel_args->num_args; ++i) {
@@ -243,7 +248,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx,
243
248
  static void destroy_channel_elem(grpc_exec_ctx* exec_ctx,
244
249
  grpc_channel_element* elem) {
245
250
  channel_data* chand = elem->channel_data;
246
- grpc_mdstr_hash_table_unref(exec_ctx, chand->method_limit_table);
251
+ grpc_slice_hash_table_unref(exec_ctx, chand->method_limit_table);
247
252
  }
248
253
 
249
254
  const grpc_channel_filter grpc_message_size_filter = {