Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [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 | |
| 33 | #include "src/core/channel/http_client_filter.h" |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 34 | #include <string.h> |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 35 | #include <grpc/support/alloc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | #include <grpc/support/log.h> |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 37 | #include <grpc/support/string_util.h> |
| 38 | #include "src/core/support/string.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | |
Yang Gao | 5fd0d29 | 2015-01-26 00:19:48 -0800 | [diff] [blame] | 40 | typedef struct call_data { |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 41 | grpc_linked_mdelem method; |
| 42 | grpc_linked_mdelem scheme; |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 43 | grpc_linked_mdelem authority; |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 44 | grpc_linked_mdelem te_trailers; |
| 45 | grpc_linked_mdelem content_type; |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 46 | grpc_linked_mdelem user_agent; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 47 | int sent_initial_metadata; |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 48 | int sent_authority; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 49 | |
| 50 | int got_initial_metadata; |
| 51 | grpc_stream_op_buffer *recv_ops; |
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 */ |
| 54 | grpc_iomgr_closure *on_done_recv; |
| 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 | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 58 | grpc_iomgr_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 | |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 61 | typedef struct channel_data { |
| 62 | grpc_mdelem *te_trailers; |
| 63 | grpc_mdelem *method; |
| 64 | grpc_mdelem *scheme; |
| 65 | grpc_mdelem *content_type; |
Craig Tiller | 5b9efed | 2015-02-03 20:13:06 -0800 | [diff] [blame] | 66 | grpc_mdelem *status; |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 67 | grpc_mdelem *default_authority; |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 68 | /** complete user agent mdelem */ |
| 69 | grpc_mdelem *user_agent; |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 70 | } channel_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 71 | |
| 72 | /* used to silence 'variable not used' warnings */ |
| 73 | static void ignore_unused(void *ignored) {} |
| 74 | |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 75 | static grpc_mdelem *client_filter(void *user_data, grpc_mdelem *md) { |
| 76 | grpc_call_element *elem = user_data; |
| 77 | channel_data *channeld = elem->channel_data; |
| 78 | if (md == channeld->status) { |
| 79 | return NULL; |
| 80 | } else if (md->key == channeld->status->key) { |
| 81 | grpc_call_element_send_cancel(elem); |
| 82 | return NULL; |
| 83 | } |
| 84 | return md; |
| 85 | } |
| 86 | |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 87 | static void hc_on_recv(void *user_data, int success) { |
| 88 | grpc_call_element *elem = user_data; |
| 89 | call_data *calld = elem->call_data; |
| 90 | if (success) { |
| 91 | size_t i; |
| 92 | size_t nops = calld->recv_ops->nops; |
| 93 | grpc_stream_op *ops = calld->recv_ops->ops; |
| 94 | for (i = 0; i < nops; i++) { |
| 95 | grpc_stream_op *op = &ops[i]; |
| 96 | if (op->type != GRPC_OP_METADATA) continue; |
| 97 | calld->got_initial_metadata = 1; |
| 98 | grpc_metadata_batch_filter(&op->data.metadata, client_filter, elem); |
| 99 | } |
| 100 | } |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 101 | calld->on_done_recv->cb(calld->on_done_recv->cb_arg, success); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Craig Tiller | d9ddc77 | 2015-07-10 13:00:05 -0700 | [diff] [blame] | 104 | static grpc_mdelem *client_strip_filter(void *user_data, grpc_mdelem *md) { |
| 105 | grpc_call_element *elem = user_data; |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 106 | call_data *calld = elem->call_data; |
Craig Tiller | d9ddc77 | 2015-07-10 13:00:05 -0700 | [diff] [blame] | 107 | channel_data *channeld = elem->channel_data; |
| 108 | /* eat the things we'd like to set ourselves */ |
| 109 | if (md->key == channeld->method->key) return NULL; |
| 110 | if (md->key == channeld->scheme->key) return NULL; |
| 111 | if (md->key == channeld->te_trailers->key) return NULL; |
| 112 | if (md->key == channeld->content_type->key) return NULL; |
| 113 | if (md->key == channeld->user_agent->key) return NULL; |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 114 | if (channeld->default_authority && channeld->default_authority->key == md->key) { |
| 115 | calld->sent_authority = 1; |
| 116 | } |
Craig Tiller | d9ddc77 | 2015-07-10 13:00:05 -0700 | [diff] [blame] | 117 | return md; |
| 118 | } |
| 119 | |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 120 | static void hc_mutate_op(grpc_call_element *elem, |
| 121 | grpc_transport_stream_op *op) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 122 | /* grab pointers to our data from the call element */ |
| 123 | call_data *calld = elem->call_data; |
| 124 | channel_data *channeld = elem->channel_data; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 125 | size_t i; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 126 | if (op->send_ops && !calld->sent_initial_metadata) { |
| 127 | size_t nops = op->send_ops->nops; |
| 128 | grpc_stream_op *ops = op->send_ops->ops; |
| 129 | for (i = 0; i < nops; i++) { |
| 130 | grpc_stream_op *op = &ops[i]; |
| 131 | if (op->type != GRPC_OP_METADATA) continue; |
| 132 | calld->sent_initial_metadata = 1; |
Craig Tiller | d9ddc77 | 2015-07-10 13:00:05 -0700 | [diff] [blame] | 133 | grpc_metadata_batch_filter(&op->data.metadata, client_strip_filter, elem); |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 134 | /* Send : prefixed headers, which have to be before any application |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 135 | layer headers. */ |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 136 | grpc_metadata_batch_add_head(&op->data.metadata, &calld->method, |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 137 | GRPC_MDELEM_REF(channeld->method)); |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 138 | grpc_metadata_batch_add_head(&op->data.metadata, &calld->scheme, |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 139 | GRPC_MDELEM_REF(channeld->scheme)); |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 140 | if (channeld->default_authority && !calld->sent_authority) { |
| 141 | grpc_metadata_batch_add_head(&op->data.metadata, &calld->authority, GRPC_MDELEM_REF(channeld->default_authority)); |
| 142 | } |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 143 | grpc_metadata_batch_add_tail(&op->data.metadata, &calld->te_trailers, |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 144 | GRPC_MDELEM_REF(channeld->te_trailers)); |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 145 | grpc_metadata_batch_add_tail(&op->data.metadata, &calld->content_type, |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 146 | GRPC_MDELEM_REF(channeld->content_type)); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 147 | grpc_metadata_batch_add_tail(&op->data.metadata, &calld->user_agent, |
| 148 | GRPC_MDELEM_REF(channeld->user_agent)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 149 | break; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 150 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 151 | } |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 152 | |
| 153 | if (op->recv_ops && !calld->got_initial_metadata) { |
| 154 | /* substitute our callback for the higher callback */ |
| 155 | calld->recv_ops = op->recv_ops; |
| 156 | calld->on_done_recv = op->on_done_recv; |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 157 | op->on_done_recv = &calld->hc_on_recv; |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 158 | } |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 159 | } |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 160 | |
Craig Tiller | 06aeea7 | 2015-04-23 10:54:45 -0700 | [diff] [blame] | 161 | static void hc_start_transport_op(grpc_call_element *elem, |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 162 | grpc_transport_stream_op *op) { |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 163 | GRPC_CALL_LOG_OP(GPR_INFO, elem, op); |
| 164 | hc_mutate_op(elem, op); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 165 | grpc_call_next_op(elem, op); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 168 | /* Constructor for call_data */ |
| 169 | static void init_call_elem(grpc_call_element *elem, |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 170 | const void *server_transport_data, |
Craig Tiller | b7959a0 | 2015-06-25 08:50:54 -0700 | [diff] [blame] | 171 | grpc_transport_stream_op *initial_op) { |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 172 | call_data *calld = elem->call_data; |
| 173 | calld->sent_initial_metadata = 0; |
| 174 | calld->got_initial_metadata = 0; |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 175 | calld->sent_authority = 0; |
Craig Tiller | 1e6facb | 2015-06-11 22:47:11 -0700 | [diff] [blame] | 176 | calld->on_done_recv = NULL; |
| 177 | grpc_iomgr_closure_init(&calld->hc_on_recv, hc_on_recv, elem); |
Craig Tiller | 50d9db5 | 2015-04-23 10:52:14 -0700 | [diff] [blame] | 178 | if (initial_op) hc_mutate_op(elem, initial_op); |
Craig Tiller | 83f88d9 | 2015-04-21 16:02:05 -0700 | [diff] [blame] | 179 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 180 | |
| 181 | /* Destructor for call_data */ |
| 182 | static void destroy_call_elem(grpc_call_element *elem) { |
| 183 | /* grab pointers to our data from the call element */ |
| 184 | call_data *calld = elem->call_data; |
| 185 | channel_data *channeld = elem->channel_data; |
| 186 | |
| 187 | ignore_unused(calld); |
| 188 | ignore_unused(channeld); |
| 189 | } |
| 190 | |
David Klempner | ed0cbc8 | 2015-01-14 14:46:10 -0800 | [diff] [blame] | 191 | static const char *scheme_from_args(const grpc_channel_args *args) { |
Nicolas "Pixel" Noble | 213ed91 | 2015-01-30 02:11:35 +0100 | [diff] [blame] | 192 | unsigned i; |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 193 | if (args != NULL) { |
| 194 | for (i = 0; i < args->num_args; ++i) { |
| 195 | if (args->args[i].type == GRPC_ARG_STRING && |
David Klempner | ed0cbc8 | 2015-01-14 14:46:10 -0800 | [diff] [blame] | 196 | strcmp(args->args[i].key, GRPC_ARG_HTTP2_SCHEME) == 0) { |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 197 | return args->args[i].value.string; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | return "http"; |
| 202 | } |
| 203 | |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 204 | static grpc_mdstr *user_agent_from_args(grpc_mdctx *mdctx, |
| 205 | const grpc_channel_args *args) { |
| 206 | gpr_strvec v; |
| 207 | size_t i; |
| 208 | int is_first = 1; |
| 209 | char *tmp; |
| 210 | grpc_mdstr *result; |
| 211 | |
| 212 | gpr_strvec_init(&v); |
| 213 | |
| 214 | for (i = 0; args && i < args->num_args; i++) { |
| 215 | if (0 == strcmp(args->args[i].key, GRPC_ARG_PRIMARY_USER_AGENT_STRING)) { |
| 216 | if (args->args[i].type != GRPC_ARG_STRING) { |
| 217 | gpr_log(GPR_ERROR, "Channel argument '%s' should be a string", |
| 218 | GRPC_ARG_PRIMARY_USER_AGENT_STRING); |
| 219 | } else { |
| 220 | if (!is_first) gpr_strvec_add(&v, gpr_strdup(" ")); |
| 221 | is_first = 0; |
| 222 | gpr_strvec_add(&v, gpr_strdup(args->args[i].value.string)); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | gpr_asprintf(&tmp, "%sgrpc-c/%s (%s)", is_first ? "" : " ", |
| 228 | grpc_version_string(), GPR_PLATFORM_STRING); |
| 229 | is_first = 0; |
| 230 | gpr_strvec_add(&v, tmp); |
| 231 | |
| 232 | for (i = 0; args && i < args->num_args; i++) { |
| 233 | if (0 == strcmp(args->args[i].key, GRPC_ARG_SECONDARY_USER_AGENT_STRING)) { |
| 234 | if (args->args[i].type != GRPC_ARG_STRING) { |
| 235 | gpr_log(GPR_ERROR, "Channel argument '%s' should be a string", |
| 236 | GRPC_ARG_SECONDARY_USER_AGENT_STRING); |
| 237 | } else { |
| 238 | if (!is_first) gpr_strvec_add(&v, gpr_strdup(" ")); |
| 239 | is_first = 0; |
| 240 | gpr_strvec_add(&v, gpr_strdup(args->args[i].value.string)); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | tmp = gpr_strvec_flatten(&v, NULL); |
| 246 | gpr_strvec_destroy(&v); |
| 247 | result = grpc_mdstr_from_string(mdctx, tmp); |
| 248 | gpr_free(tmp); |
| 249 | |
| 250 | return result; |
| 251 | } |
| 252 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 253 | /* Constructor for channel_data */ |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 254 | static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 255 | const grpc_channel_args *channel_args, grpc_mdctx *mdctx, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 256 | int is_first, int is_last) { |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 257 | size_t i; |
| 258 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 259 | /* grab pointers to our data from the channel element */ |
| 260 | channel_data *channeld = elem->channel_data; |
| 261 | |
| 262 | /* The first and the last filters tend to be implemented differently to |
| 263 | handle the case that there's no 'next' filter to call on the up or down |
| 264 | path */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 265 | GPR_ASSERT(!is_last); |
| 266 | |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 267 | channeld->default_authority = NULL; |
| 268 | if (channel_args) { |
| 269 | for (i = 0; i < channel_args->num_args; i++) { |
| 270 | if (0 == |
| 271 | strcmp(channel_args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) { |
| 272 | if (channel_args->args[i].type != GRPC_ARG_STRING) { |
| 273 | gpr_log(GPR_ERROR, "%s: must be an string", |
| 274 | GRPC_ARG_MAX_CONCURRENT_STREAMS); |
| 275 | } else { |
| 276 | channeld->default_authority = grpc_mdelem_from_strings(mdctx, ":authority", channel_args->args[i].value.string); |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 282 | /* initialize members */ |
| 283 | channeld->te_trailers = grpc_mdelem_from_strings(mdctx, "te", "trailers"); |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 284 | channeld->method = grpc_mdelem_from_strings(mdctx, ":method", "POST"); |
David Klempner | a1e8693 | 2015-01-13 18:13:59 -0800 | [diff] [blame] | 285 | channeld->scheme = |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 286 | grpc_mdelem_from_strings(mdctx, ":scheme", scheme_from_args(channel_args)); |
klempner | c463f74 | 2014-12-19 13:03:35 -0800 | [diff] [blame] | 287 | channeld->content_type = |
| 288 | grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc"); |
Craig Tiller | 5b9efed | 2015-02-03 20:13:06 -0800 | [diff] [blame] | 289 | channeld->status = grpc_mdelem_from_strings(mdctx, ":status", "200"); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 290 | channeld->user_agent = grpc_mdelem_from_metadata_strings( |
| 291 | mdctx, grpc_mdstr_from_string(mdctx, "user-agent"), |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 292 | user_agent_from_args(mdctx, channel_args)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* Destructor for channel data */ |
| 296 | static void destroy_channel_elem(grpc_channel_element *elem) { |
| 297 | /* grab pointers to our data from the channel element */ |
| 298 | channel_data *channeld = elem->channel_data; |
| 299 | |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 300 | GRPC_MDELEM_UNREF(channeld->te_trailers); |
| 301 | GRPC_MDELEM_UNREF(channeld->method); |
| 302 | GRPC_MDELEM_UNREF(channeld->scheme); |
| 303 | GRPC_MDELEM_UNREF(channeld->content_type); |
| 304 | GRPC_MDELEM_UNREF(channeld->status); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 305 | GRPC_MDELEM_UNREF(channeld->user_agent); |
Craig Tiller | 26b3714 | 2015-07-26 12:53:27 -0700 | [diff] [blame^] | 306 | if (channeld->default_authority) { |
| 307 | GRPC_MDELEM_UNREF(channeld->default_authority); |
| 308 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | const grpc_channel_filter grpc_http_client_filter = { |
Craig Tiller | e039f03 | 2015-06-25 12:54:23 -0700 | [diff] [blame] | 312 | hc_start_transport_op, grpc_channel_next_op, sizeof(call_data), |
| 313 | init_call_elem, destroy_call_elem, sizeof(channel_data), |
Craig Tiller | 1b22b9d | 2015-07-20 13:42:22 -0700 | [diff] [blame] | 314 | init_channel_elem, destroy_channel_elem, grpc_call_next_get_peer, |
| 315 | "http-client"}; |