Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 2 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
| 8 | * |
| 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following disclaimer |
| 13 | * in the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * * Neither the name of Google Inc. nor the names of its |
| 16 | * contributors may be used to endorse or promote products derived from |
| 17 | * this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | * |
| 31 | */ |
| 32 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 33 | #include "src/core/lib/channel/http_client_filter.h" |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 34 | #include <grpc/support/alloc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 35 | #include <grpc/support/log.h> |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 36 | #include <grpc/support/string_util.h> |
yang-g | d88e1d8 | 2015-12-02 13:23:33 -0800 | [diff] [blame] | 37 | #include <string.h> |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 38 | #include "src/core/lib/profiling/timers.h" |
| 39 | #include "src/core/lib/support/string.h" |
| 40 | #include "src/core/lib/transport/static_metadata.h" |
Craig Tiller | 9d69e80 | 2016-06-06 11:37:50 -0700 | [diff] [blame^] | 41 | #include "src/core/lib/transport/transport_impl.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 42 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 43 | typedef struct call_data { |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 44 | grpc_linked_mdelem method; |
| 45 | grpc_linked_mdelem scheme; |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame] | 46 | grpc_linked_mdelem authority; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 47 | grpc_linked_mdelem te_trailers; |
| 48 | grpc_linked_mdelem content_type; |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 49 | grpc_linked_mdelem user_agent; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 50 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 51 | grpc_metadata_batch *recv_initial_metadata; |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 52 | |
Craig Tiller | 98bf7e6 | 2015-06-24 08:47:07 -0700 | [diff] [blame] | 53 | /** Closure to call when finished with the hc_on_recv hook */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 54 | grpc_closure *on_done_recv; |
Craig Tiller | 98bf7e6 | 2015-06-24 08:47:07 -0700 | [diff] [blame] | 55 | /** Receive closures are chained: we inject this closure as the on_done_recv |
| 56 | up-call on transport_op, and remember to call our on_done_recv member |
| 57 | after handling it. */ |
Craig Tiller | 3382511 | 2015-09-18 07:44:19 -0700 | [diff] [blame] | 58 | grpc_closure hc_on_recv; |
Yang Gao | 5fd0d29 | 2015-01-26 00:19:48 -0800 | [diff] [blame] | 59 | } call_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 60 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 61 | typedef struct channel_data { |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 62 | grpc_mdelem *static_scheme; |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 63 | grpc_mdelem *user_agent; |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 64 | } channel_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 65 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 66 | typedef struct { |
Craig Tiller | d1bec03 | 2015-09-18 17:29:00 -0700 | [diff] [blame] | 67 | grpc_call_element *elem; |
Craig Tiller | 8af4c33 | 2015-09-22 12:32:31 -0700 | [diff] [blame] | 68 | grpc_exec_ctx *exec_ctx; |
Craig Tiller | 10ee274 | 2015-09-22 09:25:57 -0700 | [diff] [blame] | 69 | } client_recv_filter_args; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 70 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 71 | static grpc_mdelem *client_recv_filter(void *user_data, grpc_mdelem *md) { |
Craig Tiller | 10ee274 | 2015-09-22 09:25:57 -0700 | [diff] [blame] | 72 | client_recv_filter_args *a = user_data; |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 73 | if (md == GRPC_MDELEM_STATUS_200) { |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 74 | return NULL; |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 75 | } else if (md->key == GRPC_MDSTR_STATUS) { |
| 76 | grpc_call_element_send_cancel(a->exec_ctx, a->elem); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 77 | return NULL; |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 78 | } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 79 | return NULL; |
| 80 | } |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 81 | return md; |
| 82 | } |
| 83 | |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 84 | static void hc_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, bool success) { |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 85 | grpc_call_element *elem = user_data; |
| 86 | call_data *calld = elem->call_data; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 87 | client_recv_filter_args a; |
| 88 | a.elem = elem; |
| 89 | a.exec_ctx = exec_ctx; |
| 90 | grpc_metadata_batch_filter(calld->recv_initial_metadata, client_recv_filter, |
| 91 | &a); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 92 | calld->on_done_recv->cb(exec_ctx, calld->on_done_recv->cb_arg, success); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 95 | static grpc_mdelem *client_strip_filter(void *user_data, grpc_mdelem *md) { |
Craig Tiller | d9ddc77 | 2015-07-10 13:00:05 -0700 | [diff] [blame] | 96 | /* eat the things we'd like to set ourselves */ |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 97 | if (md->key == GRPC_MDSTR_METHOD) return NULL; |
| 98 | if (md->key == GRPC_MDSTR_SCHEME) return NULL; |
| 99 | if (md->key == GRPC_MDSTR_TE) return NULL; |
| 100 | if (md->key == GRPC_MDSTR_CONTENT_TYPE) return NULL; |
| 101 | if (md->key == GRPC_MDSTR_USER_AGENT) return NULL; |
Craig Tiller | d9ddc77 | 2015-07-10 13:00:05 -0700 | [diff] [blame] | 102 | return md; |
| 103 | } |
| 104 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 105 | static void hc_mutate_op(grpc_call_element *elem, |
| 106 | grpc_transport_stream_op *op) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 107 | /* grab pointers to our data from the call element */ |
| 108 | call_data *calld = elem->call_data; |
| 109 | channel_data *channeld = elem->channel_data; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 110 | if (op->send_initial_metadata != NULL) { |
| 111 | grpc_metadata_batch_filter(op->send_initial_metadata, client_strip_filter, |
| 112 | elem); |
| 113 | /* Send : prefixed headers, which have to be before any application |
| 114 | layer headers. */ |
Craig Tiller | 8c0d96f | 2016-03-11 14:27:52 -0800 | [diff] [blame] | 115 | grpc_metadata_batch_add_head( |
| 116 | op->send_initial_metadata, &calld->method, |
| 117 | op->send_initial_metadata_flags & |
| 118 | GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST |
| 119 | ? GRPC_MDELEM_METHOD_PUT |
| 120 | : GRPC_MDELEM_METHOD_POST); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 121 | grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->scheme, |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 122 | channeld->static_scheme); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 123 | grpc_metadata_batch_add_tail(op->send_initial_metadata, &calld->te_trailers, |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 124 | GRPC_MDELEM_TE_TRAILERS); |
| 125 | grpc_metadata_batch_add_tail( |
| 126 | op->send_initial_metadata, &calld->content_type, |
| 127 | GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC); |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 128 | grpc_metadata_batch_add_tail(op->send_initial_metadata, &calld->user_agent, |
| 129 | GRPC_MDELEM_REF(channeld->user_agent)); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 130 | } |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 131 | |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 132 | if (op->recv_initial_metadata != NULL) { |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 133 | /* substitute our callback for the higher callback */ |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 134 | calld->recv_initial_metadata = op->recv_initial_metadata; |
Craig Tiller | a44cbfc | 2016-02-03 16:02:49 -0800 | [diff] [blame] | 135 | calld->on_done_recv = op->recv_initial_metadata_ready; |
| 136 | op->recv_initial_metadata_ready = &calld->hc_on_recv; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 137 | } |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 138 | } |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 139 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 140 | static void hc_start_transport_op(grpc_exec_ctx *exec_ctx, |
| 141 | grpc_call_element *elem, |
| 142 | grpc_transport_stream_op *op) { |
Craig Tiller | 0ba432d | 2015-10-09 16:57:11 -0700 | [diff] [blame] | 143 | GPR_TIMER_BEGIN("hc_start_transport_op", 0); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 144 | GRPC_CALL_LOG_OP(GPR_INFO, elem, op); |
| 145 | hc_mutate_op(elem, op); |
Craig Tiller | 0ba432d | 2015-10-09 16:57:11 -0700 | [diff] [blame] | 146 | GPR_TIMER_END("hc_start_transport_op", 0); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 147 | grpc_call_next_op(exec_ctx, elem, op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 150 | /* Constructor for call_data */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 151 | static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 152 | grpc_call_element_args *args) { |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 153 | call_data *calld = elem->call_data; |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 154 | calld->on_done_recv = NULL; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 155 | grpc_closure_init(&calld->hc_on_recv, hc_on_recv, elem); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 156 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 157 | |
| 158 | /* Destructor for call_data */ |
Craig Tiller | 2c8063c | 2016-03-22 22:12:15 -0700 | [diff] [blame] | 159 | static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, |
| 160 | void *ignored) {} |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 161 | |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 162 | static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) { |
Nicolas "Pixel" Noble | 213ed91 | 2015-01-30 02:11:35 +0100 | [diff] [blame] | 163 | unsigned i; |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 164 | size_t j; |
| 165 | grpc_mdelem *valid_schemes[] = {GRPC_MDELEM_SCHEME_HTTP, |
| 166 | GRPC_MDELEM_SCHEME_HTTPS}; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 167 | if (args != NULL) { |
| 168 | for (i = 0; i < args->num_args; ++i) { |
| 169 | if (args->args[i].type == GRPC_ARG_STRING && |
| 170 | strcmp(args->args[i].key, GRPC_ARG_HTTP2_SCHEME) == 0) { |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 171 | for (j = 0; j < GPR_ARRAY_SIZE(valid_schemes); j++) { |
| 172 | if (0 == strcmp(grpc_mdstr_as_c_string(valid_schemes[j]->value), |
| 173 | args->args[i].value.string)) { |
| 174 | return valid_schemes[j]; |
| 175 | } |
| 176 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 177 | } |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 178 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 179 | } |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 180 | return GRPC_MDELEM_SCHEME_HTTP; |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Craig Tiller | 9d69e80 | 2016-06-06 11:37:50 -0700 | [diff] [blame^] | 183 | static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args, |
| 184 | const char *transport_name) { |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 185 | gpr_strvec v; |
| 186 | size_t i; |
| 187 | int is_first = 1; |
| 188 | char *tmp; |
| 189 | grpc_mdstr *result; |
| 190 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 191 | gpr_strvec_init(&v); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 192 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 193 | for (i = 0; args && i < args->num_args; i++) { |
| 194 | if (0 == strcmp(args->args[i].key, GRPC_ARG_PRIMARY_USER_AGENT_STRING)) { |
| 195 | if (args->args[i].type != GRPC_ARG_STRING) { |
| 196 | gpr_log(GPR_ERROR, "Channel argument '%s' should be a string", |
| 197 | GRPC_ARG_PRIMARY_USER_AGENT_STRING); |
| 198 | } else { |
| 199 | if (!is_first) gpr_strvec_add(&v, gpr_strdup(" ")); |
| 200 | is_first = 0; |
| 201 | gpr_strvec_add(&v, gpr_strdup(args->args[i].value.string)); |
| 202 | } |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 203 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 204 | } |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 205 | |
Craig Tiller | 9d69e80 | 2016-06-06 11:37:50 -0700 | [diff] [blame^] | 206 | gpr_asprintf(&tmp, "%sgrpc-c/%s (%s; %s)", is_first ? "" : " ", |
| 207 | grpc_version_string(), GPR_PLATFORM_STRING, transport_name); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 208 | is_first = 0; |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 209 | gpr_strvec_add(&v, tmp); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 210 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 211 | for (i = 0; args && i < args->num_args; i++) { |
| 212 | if (0 == strcmp(args->args[i].key, GRPC_ARG_SECONDARY_USER_AGENT_STRING)) { |
| 213 | if (args->args[i].type != GRPC_ARG_STRING) { |
| 214 | gpr_log(GPR_ERROR, "Channel argument '%s' should be a string", |
| 215 | GRPC_ARG_SECONDARY_USER_AGENT_STRING); |
| 216 | } else { |
| 217 | if (!is_first) gpr_strvec_add(&v, gpr_strdup(" ")); |
| 218 | is_first = 0; |
| 219 | gpr_strvec_add(&v, gpr_strdup(args->args[i].value.string)); |
| 220 | } |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 221 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 222 | } |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 223 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 224 | tmp = gpr_strvec_flatten(&v, NULL); |
| 225 | gpr_strvec_destroy(&v); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 226 | result = grpc_mdstr_from_string(tmp); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 227 | gpr_free(tmp); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 228 | |
| 229 | return result; |
| 230 | } |
| 231 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 232 | /* Constructor for channel_data */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 233 | static void init_channel_elem(grpc_exec_ctx *exec_ctx, |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 234 | grpc_channel_element *elem, |
| 235 | grpc_channel_element_args *args) { |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 236 | channel_data *chand = elem->channel_data; |
Craig Tiller | 577c9b2 | 2015-11-02 14:11:15 -0800 | [diff] [blame] | 237 | GPR_ASSERT(!args->is_last); |
Craig Tiller | 9d69e80 | 2016-06-06 11:37:50 -0700 | [diff] [blame^] | 238 | GPR_ASSERT(args->optional_transport != NULL); |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 239 | chand->static_scheme = scheme_from_args(args->channel_args); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 240 | chand->user_agent = grpc_mdelem_from_metadata_strings( |
Craig Tiller | 9d69e80 | 2016-06-06 11:37:50 -0700 | [diff] [blame^] | 241 | GRPC_MDSTR_USER_AGENT, |
| 242 | user_agent_from_args(args->channel_args, |
| 243 | args->optional_transport->vtable->name)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /* Destructor for channel data */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 247 | static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, |
| 248 | grpc_channel_element *elem) { |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 249 | channel_data *chand = elem->channel_data; |
| 250 | GRPC_MDELEM_UNREF(chand->user_agent); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | const grpc_channel_filter grpc_http_client_filter = { |
Craig Tiller | f40df23 | 2016-03-25 13:38:14 -0700 | [diff] [blame] | 254 | hc_start_transport_op, |
| 255 | grpc_channel_next_op, |
| 256 | sizeof(call_data), |
| 257 | init_call_elem, |
| 258 | grpc_call_stack_ignore_set_pollset, |
| 259 | destroy_call_elem, |
| 260 | sizeof(channel_data), |
| 261 | init_channel_elem, |
| 262 | destroy_channel_elem, |
| 263 | grpc_call_next_get_peer, |
| 264 | "http-client"}; |