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.
- checksums.yaml +4 -4
- data/Makefile +1257 -404
- data/etc/roots.pem +189 -102
- data/include/grpc/census.h +7 -7
- data/include/grpc/compression.h +4 -4
- data/include/grpc/grpc.h +13 -7
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
- data/include/grpc/impl/codegen/grpc_types.h +39 -30
- data/include/grpc/impl/codegen/slice.h +24 -6
- data/include/grpc/impl/codegen/sync.h +8 -0
- data/include/grpc/load_reporting.h +63 -0
- data/include/grpc/slice.h +37 -1
- data/include/grpc/slice_buffer.h +7 -0
- data/include/grpc/support/alloc.h +3 -0
- data/include/grpc/support/useful.h +3 -0
- data/src/core/ext/census/gen/census.pb.h +1 -1
- data/src/core/ext/census/gen/trace_context.pb.c +9 -36
- data/src/core/ext/census/gen/trace_context.pb.h +20 -26
- data/src/core/ext/census/grpc_filter.c +3 -5
- data/src/core/ext/census/trace_context.c +1 -1
- data/src/core/ext/census/trace_context.h +3 -0
- data/src/core/ext/census/trace_label.h +61 -0
- data/src/core/ext/census/trace_propagation.h +63 -0
- data/src/core/ext/census/trace_status.h +45 -0
- data/src/core/ext/census/trace_string.h +50 -0
- data/src/core/ext/census/tracing.c +31 -11
- data/src/core/ext/census/tracing.h +124 -0
- data/src/core/ext/client_channel/client_channel.c +456 -368
- data/src/core/ext/client_channel/client_channel.h +4 -0
- data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
- data/src/core/ext/client_channel/connector.c +3 -3
- data/src/core/ext/client_channel/connector.h +4 -3
- data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
- data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
- data/src/core/ext/client_channel/http_proxy.c +125 -0
- data/src/core/ext/client_channel/http_proxy.h +39 -0
- data/src/core/ext/client_channel/lb_policy.c +56 -35
- data/src/core/ext/client_channel/lb_policy.h +46 -39
- data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
- data/src/core/ext/client_channel/parse_address.c +32 -6
- data/src/core/ext/client_channel/proxy_mapper.c +63 -0
- data/src/core/ext/client_channel/proxy_mapper.h +89 -0
- data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
- data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
- data/src/core/ext/client_channel/resolver.c +16 -9
- data/src/core/ext/client_channel/resolver.h +23 -12
- data/src/core/ext/client_channel/resolver_factory.h +1 -0
- data/src/core/ext/client_channel/resolver_registry.c +15 -11
- data/src/core/ext/client_channel/resolver_registry.h +5 -3
- data/src/core/ext/client_channel/subchannel.c +44 -27
- data/src/core/ext/client_channel/subchannel.h +6 -2
- data/src/core/ext/client_channel/uri_parser.c +26 -14
- data/src/core/ext/client_channel/uri_parser.h +3 -1
- data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
- data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
- data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
- data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
- data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
- data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
- data/src/core/ext/load_reporting/load_reporting.c +20 -0
- data/src/core/ext/load_reporting/load_reporting.h +1 -16
- data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
- data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
- data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
- data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
- data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
- data/src/core/lib/channel/channel_stack.c +14 -44
- data/src/core/lib/channel/channel_stack.h +10 -17
- data/src/core/lib/channel/channel_stack_builder.c +2 -3
- data/src/core/lib/channel/compress_filter.c +54 -46
- data/src/core/lib/channel/connected_channel.c +4 -4
- data/src/core/lib/channel/connected_channel.h +5 -0
- data/src/core/lib/channel/context.h +3 -0
- data/src/core/lib/channel/deadline_filter.c +61 -61
- data/src/core/lib/channel/deadline_filter.h +8 -5
- data/src/core/lib/channel/handshaker.c +47 -7
- data/src/core/lib/channel/handshaker.h +21 -3
- data/src/core/lib/channel/http_client_filter.c +149 -99
- data/src/core/lib/channel/http_server_filter.c +163 -147
- data/src/core/lib/channel/message_size_filter.c +15 -10
- data/src/core/lib/compression/algorithm_metadata.h +4 -4
- data/src/core/lib/compression/compression.c +17 -23
- data/src/core/lib/http/httpcli.c +3 -2
- data/src/core/lib/http/httpcli.h +2 -1
- data/src/core/lib/http/httpcli_security_connector.c +2 -3
- data/src/core/lib/http/parser.c +2 -2
- data/src/core/lib/iomgr/closure.c +6 -3
- data/src/core/lib/iomgr/closure.h +4 -2
- data/src/core/lib/iomgr/combiner.c +35 -5
- data/src/core/lib/iomgr/combiner.h +21 -2
- data/src/core/lib/iomgr/endpoint.c +3 -2
- data/src/core/lib/iomgr/endpoint.h +3 -2
- data/src/core/lib/iomgr/error.c +60 -94
- data/src/core/lib/iomgr/error.h +7 -10
- data/src/core/lib/iomgr/error_internal.h +54 -0
- data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
- data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
- data/src/core/lib/iomgr/ev_posix.c +7 -8
- data/src/core/lib/iomgr/ev_posix.h +4 -4
- data/src/core/lib/iomgr/exec_ctx.c +11 -6
- data/src/core/lib/iomgr/exec_ctx.h +11 -14
- data/src/core/lib/iomgr/executor.c +2 -2
- data/src/core/lib/iomgr/load_file.c +1 -1
- data/src/core/lib/iomgr/network_status_tracker.c +5 -81
- data/src/core/lib/iomgr/pollset.h +1 -3
- data/src/core/lib/iomgr/pollset_set.h +2 -1
- data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
- data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
- data/src/core/lib/iomgr/pollset_uv.c +25 -11
- data/src/core/lib/iomgr/pollset_windows.c +0 -11
- data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
- data/src/core/lib/iomgr/resource_quota.c +41 -11
- data/src/core/lib/iomgr/resource_quota.h +6 -0
- data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
- data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
- data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
- data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
- data/src/core/lib/iomgr/tcp_posix.c +4 -5
- data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
- data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
- data/src/core/lib/iomgr/tcp_uv.c +11 -5
- data/src/core/lib/iomgr/tcp_windows.c +20 -7
- data/src/core/lib/iomgr/timer_generic.c +15 -22
- data/src/core/lib/iomgr/timer_generic.h +1 -1
- data/src/core/lib/iomgr/timer_uv.c +10 -6
- data/src/core/lib/iomgr/timer_uv.h +1 -1
- data/src/core/lib/iomgr/udp_server.c +45 -6
- data/src/core/lib/iomgr/udp_server.h +7 -1
- data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
- data/src/core/lib/json/json.c +1 -2
- data/src/core/lib/profiling/basic_timers.c +17 -3
- data/src/core/lib/security/context/security_context.c +3 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
- data/src/core/lib/security/credentials/credentials.c +48 -2
- data/src/core/lib/security/credentials/credentials.h +13 -0
- data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
- data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
- data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
- data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
- data/src/core/lib/security/transport/client_auth_filter.c +72 -47
- data/src/core/lib/security/transport/lb_targets_info.c +70 -0
- data/src/core/lib/security/transport/lb_targets_info.h +47 -0
- data/src/core/lib/security/transport/secure_endpoint.c +3 -3
- data/src/core/lib/security/transport/security_connector.c +125 -28
- data/src/core/lib/security/transport/security_connector.h +4 -3
- data/src/core/lib/security/transport/security_handshaker.c +13 -9
- data/src/core/lib/security/transport/server_auth_filter.c +31 -40
- data/src/core/lib/security/util/b64.c +1 -1
- data/src/core/lib/slice/slice.c +110 -20
- data/src/core/lib/slice/slice_buffer.c +92 -39
- data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
- data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
- data/src/core/lib/slice/slice_intern.c +346 -0
- data/src/core/lib/slice/slice_internal.h +15 -0
- data/src/core/lib/slice/slice_string_helpers.c +5 -0
- data/src/core/lib/slice/slice_string_helpers.h +5 -0
- data/src/core/lib/support/alloc.c +26 -1
- data/src/core/lib/support/cmdline.c +2 -4
- data/src/core/lib/support/cpu_posix.c +2 -7
- data/src/core/lib/support/histogram.c +1 -2
- data/src/core/lib/support/log_posix.c +8 -4
- data/src/core/lib/support/spinlock.h +52 -0
- data/src/core/lib/support/subprocess_posix.c +1 -2
- data/src/core/lib/support/sync.c +7 -1
- data/src/core/lib/support/sync_posix.c +9 -0
- data/src/core/lib/support/time_windows.c +7 -1
- data/src/core/lib/surface/call.c +647 -629
- data/src/core/lib/surface/call.h +4 -1
- data/src/core/lib/surface/call_details.c +8 -2
- data/src/core/lib/surface/call_log_batch.c +17 -6
- data/src/core/lib/surface/channel.c +49 -59
- data/src/core/lib/surface/channel.h +5 -6
- data/src/core/lib/surface/completion_queue.c +16 -45
- data/src/core/lib/surface/completion_queue.h +0 -3
- data/src/core/lib/surface/init.c +6 -2
- data/src/core/lib/surface/init_secure.c +1 -1
- data/src/core/lib/surface/lame_client.c +14 -4
- data/src/core/lib/surface/server.c +79 -82
- data/src/core/lib/surface/validate_metadata.c +46 -15
- data/src/core/lib/surface/validate_metadata.h +43 -0
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/bdp_estimator.c +104 -0
- data/src/core/lib/transport/bdp_estimator.h +76 -0
- data/src/core/lib/transport/connectivity_state.c +33 -13
- data/src/core/lib/transport/connectivity_state.h +15 -5
- data/src/core/lib/transport/error_utils.c +124 -0
- data/src/core/lib/transport/error_utils.h +56 -0
- data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
- data/src/core/lib/transport/metadata.c +259 -503
- data/src/core/lib/transport/metadata.h +69 -68
- data/src/core/lib/transport/metadata_batch.c +183 -63
- data/src/core/lib/transport/metadata_batch.h +50 -26
- data/src/core/lib/transport/pid_controller.c +28 -8
- data/src/core/lib/transport/pid_controller.h +15 -2
- data/src/core/lib/transport/service_config.c +21 -18
- data/src/core/lib/transport/service_config.h +5 -5
- data/src/core/lib/transport/static_metadata.c +753 -112
- data/src/core/lib/transport/static_metadata.h +403 -264
- data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
- data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
- data/src/core/lib/transport/timeout_encoding.c +11 -9
- data/src/core/lib/transport/timeout_encoding.h +3 -1
- data/src/core/lib/transport/transport.c +47 -87
- data/src/core/lib/transport/transport.h +20 -25
- data/src/core/lib/transport/transport_op_string.c +7 -19
- data/src/core/lib/tsi/fake_transport_security.c +2 -4
- data/src/core/lib/tsi/ssl_transport_security.c +7 -16
- data/src/core/lib/tsi/transport_security.c +2 -4
- data/src/ruby/ext/grpc/extconf.rb +4 -1
- data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
- data/src/ruby/ext/grpc/rb_call.c +47 -46
- data/src/ruby/ext/grpc/rb_channel.c +21 -6
- data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
- data/src/ruby/ext/grpc/rb_server.c +6 -4
- data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- 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
|
-
|
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
|
87
|
-
|
88
|
-
|
89
|
-
if (
|
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
|
-
|
92
|
-
|
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
|
-
|
97
|
-
|
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
|
106
|
-
|
107
|
-
|
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
|
-
|
111
|
-
|
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
|
121
|
-
|
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
|
124
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
151
|
-
} else
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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(
|
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
|
-
|
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
|
-
|
197
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
310
|
-
|
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
|
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)
|
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)
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 = {
|